
22 Nov
2010
22 Nov
'10
8:51 a.m.
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