# Observation with different shape

I am wondering if I hope to do inference for the case:

pm.Normal(‘XXX’, mu = predicted_mu (with length 10), sd = std (with length 10) , observed = data.

The data is an array of size 10 but for each elemental array in the data array, they are of different length.

May I know how to incorporate this for inference?

1 Like

Let’s see:

``````import pymc as pm
from numpy.random import default_rng
rng = default_rng()

data = np.array([rng.random(size=10),
rng.random(size=10),
rng.random(size=10)
])
print(data.shape)
# (3, 10)

with pm.Model() as model:
m = pm.Normal('m', 0, 1, shape=10)
sd = pm.HalfNormal('sd', 1, shape=10)
xxx = pm.Normal('XXX',
mu = m,
sigma = sd,
observed = data
)

idata = pm.sample()
``````

Does that work?

Sorry that I fail to make the question clearer. I am assume for a parameter theta, I am getting a vector of prediction G(theta) = [G1(theta), G2(theta), G3(theta)], I am getting 10 observations for G1 and G2 but only 5 for G3

I guess I am not clear what this means. Can you mock up a model and dataset that is close to what you want and then see where it fails/gives an error/etc.? Then we can figure out how to fix it.

If I understand you correctly, you can flatten your observations and then use indexing to match with your parameters.

Assuming just 2 means and stds, and 7 observations, 3 of which belong to the first set of parameters and 4 to the last:

``````obs = [1.1, 0.9, 2.2, 4.4, 5.5, 6.6, 6.0]
idxs = [0, 0, 0, 1, 1, 1, 1]

with pm.Model() as m:
...
pm.Normal("llike", mu=predicted_mu[idxs], sigma=std[idxs], observed=obs)
``````
2 Likes