[Numpy-discussion] categorical distributions

Hagen Fürstenau hagen@zhuliguan....
Mon Nov 22 01:51:03 CST 2010


Hi,

numpy doesn't seem to have a function for sampling from simple
categorical distributions. The easiest solution I could come up with was
something like

>>> from numpy.random import multinomial
>>> multinomial(1, [.5, .3, .2]).nonzero()[0][0]
1

but this is bound to be inefficient as soon as the vector of
probabilities gets large, especially if you want to draw multiple samples.

Have I overlooked something or should this be added?

- Hagen



More information about the NumPy-Discussion mailing list