Multiple covariance structures

Fitting models to vectors of data with two distinct means and distinct variance structures is no problem using indexing, e.g.:

import numpy as np
import pymc3 as pm
import theano.tensor as tt

#univariate data (uv)

numSubs = 2
numData = 100
idx = np.repeat(np.arange(0,numSubs),numData)

uv_sds = []
for i in np.arange(0,numSubs):
    uv_mu = np.random.randn()
    uv_sd = np.random.rand()
    uv_data.append(np.random.normal(uv_mu, uv_sd, numData))

uv_y = np.hstack(uv_data)

with pm.Model() as uv_model:
    uv_mu_prior = pm.Normal('uv_mu_prior',mu=0,sigma=1,shape=numSubs)
    uv_sd_prior = pm.Exponential('uv_sd_prior',lam=1,shape=numSubs)
    #likelihood function (lf)
    uv_lf = pm.Normal('uv_lf',mu=uv_mu_prior[idx],sigma=uv_sd_prior[idx],observed = uv_y)
    uv_trace = pm.sample(1000,tune=1000)

This fits fine, however I can’t seem to apply the same indexing logic to data with separate mutivariate structures, e.g.:

#multivariate data (mv)
numSubs = 2
numData = 100
idx = np.repeat(np.arange(0,numSubs),numData)
numVars = 2

mv_covs = []
for i in np.arange(0,numSubs):
    mv_mu = np.random.randn(numVars)
    #make a positive semi-definite matrix for covariance
    A = np.random.randn(numVars, numVars)
    mv_cov =, A.transpose())
    mv_data.append(np.random.multivariate_normal(mv_mu, mv_cov, numData))
    mv_y = np.vstack(mv_data)

with pm.Model() as mv_model:
    mu_prior = pm.Normal('mu_prior',mu=0,sigma=1,shape=(numSubs,numVars))
    sd_dist = pm.Exponential.dist(1.0, shape=(numSubs,numVars))
    chol,_,_ = pm.LKJCholeskyCov('chol', n=(numSubs,numVars), eta=1, sd_dist= sd_dist, compute_corr=True)
    vals = pm.MvNormal('vals', mu=mu_prior[idx], chol=chol[idx], observed=mv_y)
    trace = pm.sample(1000,tune=1000)

Played around with a bunch of different settings and just can’t seem to get it to work, any suggestions?