Yes, we need to write a notebook on shape handling.
Your confusion is really common. There are two quantities that characterize a mixture: the number of components (distributions that go into the mixture, in your case 2), and the shape of the outputed value (what the shape of a single call to random() is). The mixtures’ components can be specified in one of two ways:
- As a list of distributions. The len of the list specifies the number of components
- As a single multidimensional distribution. The
shape[-1]of this distribution encodes the number of components.
So what’s the mixtures’ shape? Well, if your components are scalars, like yours, your mixtures’ distribution shape should also be 1 (or left blank which is basically the same). Why did shape=2 work? Because it assumed that you were stacking 2 independent scalars that came from the same underlying mixture distribution, much like what is assumed when you do Normal(..., shape=2).
In the first case, the len of the list informs the number of mixture components
has the number of componente