[SciPy-User] vectorized version of 'multinomial' sampling function

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Oct 14 01:07:24 EDT 2009


On Tue, Oct 13, 2009 at 5:01 PM, per freem <perfreem at gmail.com> wrote:
> hi all,
>
> i have a series of probability vector that i'd like to feed into
> multinomial to get an array of vector outcomes back. for example,
> given:
>
> p = array([[ 0.9 ,  0.05,  0.05],
>       [ 0.05,  0.05,  0.9 ]])
>
> i'd like to call multinomial like this:
>
> multinomial(1, p)

If you only want n=1, then it seems to me, you could do this also with
drawing an integer out of range(3) with the given probabilities. This
can be vectorized easily directly with numpy. (just like an individual
observation in multinomial logit)

Josef

>
> to get a vector of multinomial samplers, each using the nth list in
> 'p'. something like:
>
> array([[1, 0, 0], [0, 0 1]]) in this case. is this possible? it seems
> like 'multinomial' takes only a one dimensional array. i could write
> this as a "for" loop of course but i prefer a vectorized version since
> speed is crucial for me here.
>
> thanks very much.
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list