[SciPy-User] scipy.stats pmf evaluation

nicky van foreest vanforeest at gmail.com
Sat May 14 16:06:49 EDT 2011


Hi,

I wanted to compute a probability mass function on a range and a grid
at the same time, but this fails. Here is an example.

In [1]: from scipy.stats import poisson

In [2]: import numpy as np

In [3]: print poisson.pmf(1, 1)
0.367879441171

In [4]: grid = np.arange(np.finfo(float).eps,1.1,0.1)

In [5]: print poisson.pmf(1, grid)
[  2.22044605e-16   9.04837418e-02   1.63746151e-01   2.22245466e-01
   2.68128018e-01   3.03265330e-01   3.29286982e-01   3.47609713e-01
   3.59463171e-01   3.65912694e-01   3.67879441e-01]

In [6]: print poisson.pmf(range(2), 1)
[ 0.36787944  0.36787944]


+++

Up to now everything works as expected. But this fails:

+++

In [7]: print poisson.pmf(range(2), grid)

ValueError: shape mismatch: objects cannot be broadcast to a single shape

+++

Why is the call to  poisson.pmf(range(2), grid)  wrong, while it works
on either a range or a grid?

Does anybody perhaps know the right way to compute
poisson.pmf(range(2), grid)" without using a for loop?

thanks

Nicky



More information about the SciPy-User mailing list