Declare priors using loop results in bracket nesting level exceeded maximum

Thanks for that great idea. And yes, indeed, writing the problem as a directed graph is a nice way to vectorize it. I think the following code should describe my example:

A = nx.adjacency_matrix(G).todense().T
y0_vec = np.zeros(A.shape[0])
mu = np.log(2) + np.random.normal(0,0.1,A.shape[0])
y0_R = 1.0
y0_vec[0] = y0_R * np.exp(mu[0])

res = y0_vec

for gen in range(1, n_generations + 1):
   y0_vec = A @ (np.diag(y0_vec) @ np.exp(mu) / 2)
   res += y0_vec

However, I have to admit that it is still unclear to me on how to use this with the scan method.