Pymc3 Shape Error Using pm.fast_sample_posterior_predictive

  bayesian, numpy, pymc3, python

I have fit a two-component mixture model using PYMC3, and wish to sample from the posterior model.

I am able to do so fine using pm.sample_posterior_predictive(), however when I attempt to do so using pm.fast_sample_posterior_predictive(), I receive the following ValueError:

ValueError: input operand has more dimensions than allowed by the axis remapping

I am unsure why this is, and cannot find why this might be in the PYMC3 documentation.

Code below:

with pm.Model() as model:
    alpha_mu = 1.0 / y.mean()
    lam1 = pm.Exponential('lam1', lam=1)
    lam2 = pm.Exponential('lam2', lam=2)

    pois1 = pm.Poisson.dist(mu=lam1)
    pois2 = pm.Poisson.dist(mu=lam2)

    w = pm.Dirichlet('w', a=np.array([1, 1]))

    mix = pm.Mixture('mix', w=w, comp_dists = [pois1, pois2], observed=y)
    # optimization
    mean_field =, obj_optimizer=pm.adagrad(learning_rate=0.1))
    trace = mean_field.sample(1000)
    # plot trace
    # plot Preditive Posterior Check
    ppc = pm.fast_sample_posterior_predictive(trace, samples=len(y))

Any help gratefully received, thank you.

Source: Python Questions