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

_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to