[SciPy-User] scipy.stats.poisson, strange output?

josef.pktd at gmail.com josef.pktd at gmail.com
Sat Feb 4 18:33:08 EST 2012


On Sat, Feb 4, 2012 at 6:12 PM, nicky van foreest <vanforeest at gmail.com> wrote:
> Hi,
>
> I used two types of poisson, and obtained different results. Specifically:
>
> In [1]: from scipy.stats import poisson
>
> In [2]: import numpy as np
>
> In [3]: grid = np.arange(20)
>
> In [4]: rv = poisson(10)
>
> In [5]: print rv.pmf(grid)
> [  4.53999298e-05   4.53999298e-04   2.26999649e-03   7.56665496e-03
>   1.89166374e-02   3.78332748e-02   6.30554580e-02   9.00792257e-02
>   1.12599032e-01   1.25110036e-01   1.25110036e-01   1.13736396e-01
>   9.47803301e-02   7.29079462e-02   5.20771044e-02   3.47180696e-02
>   2.16987935e-02   1.27639962e-02   7.09110899e-03   3.73216263e-03]
>
> In [6]: print poisson.pmf(10., grid)
> [             nan   1.01377712e-07   3.81898506e-05   8.10151179e-04
>   5.29247668e-03   1.81327887e-02   4.13030934e-02   7.09832687e-02
>   9.92615338e-02   1.18580076e-01   1.25110036e-01   1.19378060e-01
>   1.04837256e-01   8.58701508e-02   6.62818432e-02   4.86107508e-02
>   3.40976998e-02   2.29995844e-02   1.49851586e-02   9.46624674e-03]

wrong sequence of arguments, the shape (mean) argument should be
second and first the values at which pmf is evaluated, i.e.

>>> stats.poisson.pmf(grid, 10)
array([ 0.0000453999297625,  0.0004539992976248,  0.0022699964881242,
        0.0075666549604141,  0.0189166374010354,  0.0378332748020708,
        0.0630554580034512,  0.090079225719216 ,  0.1125990321490201,
        0.1251100357211337,  0.1251100357211337,  0.1137363961101213,
        0.094780330091768 ,  0.0729079462244373,  0.0520771044460262,
        0.0347180696306844,  0.0216987935191777,  0.0127639961877516,
        0.0070911089931953,  0.0037321626279975])

in the first case it's a frozen distribution

>>> stats.poisson(10).pmf(grid)
array([ 0.0000453999297625,  0.0004539992976248,  0.0022699964881242,
        0.0075666549604141,  0.0189166374010354,  0.0378332748020708,
        0.0630554580034512,  0.090079225719216 ,  0.1125990321490201,
        0.1251100357211337,  0.1251100357211337,  0.1137363961101213,
        0.094780330091768 ,  0.0729079462244373,  0.0520771044460262,
        0.0347180696306844,  0.0216987935191777,  0.0127639961877516,
        0.0070911089931953,  0.0037321626279975])

Josef

>
> In [7]:
>
>
> So, in line [5], rv.pmf(grid)[0] is a number, while in [6],
> poisson.pmf(10,grid)[0] is nan. Am I doing something wrong, or is this
> an unintentional inconsistency?
>
> Nicky
> _______________________________________________
> 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