How to get around using a for loop?

Here is a simplification of the current model I am using:

``````   with pm.Model() as mymodel:
precision = pm.Bound(pm.Gamma, lower=.609, upper=33.33)('precision',alpha=Cshape,beta=Crate,shape=nsubj)
mushift = pm.Bound(pm.Normal, lower=-0.2618, upper=0.2618)('mushift',mu=Cshift,sd=Ctau,shape=nsubj)
y = pm.VonMises('y', mu=mushift, kappa=precision, observed=x)
``````

I have a vector, x, of length 14,000, and a vector, m, also of length 14,000. I want to use x as the â€śobservedâ€ť input for â€śyâ€ť, and I want to add â€śmâ€ť to â€śmushiftâ€ť for each observation of â€śxâ€ť. In other words, for observation x[0] I want mu=mushift+m[0], and for observation x[1] I want mu=mushift+m[1], and so on.

How could I accomplish such a thing without resorting to using a for loop? Thanks greatly for your time, I have been going in circles for a long time trying to find a solution.

Might be easier to do

``````x_shift = x - m
x_shift = x/np.linalg.norm(x)
y = pm.VonMises('y', mu=mushift, kappa=precision, observed=x_shift)
``````

I think maybe if you set `shape=(nsubj,1)` for `m` and `mushift` then you can use `mu=mushift+m` in the VonMises arguments (an easy test is to check that `observed=x[1:]` fails).

1 Like

Youâ€™re a genius! I didnâ€™t think about changing the observed variable.