API question: What are the semantics of array-style indexing on a Distribution object, with another PyMC object?

Theano/Aesara tensors (and by extension PyMC variables) can be indexed exactly as numpy arrays. The numpy documentation on integer-array indexing should answer your question.

The long and short of it is that given some array, you can use the items in that array to create a new array of arbitrary length. In the case of the tutorial, sigma is a tensor of shape (4,), and g is a (100,) array of [0, 0, ..., 1, 1, ..., 2, 2, ... 3, 3, ...3]. Indexing sigma[g] returns a (100,) tensor where the ith element corresponds to sigma[g[i]].

Au contraire, this is a very common way to write down a hierarchical model.

2 Likes