当你使用的泊功能在Excel(或OpenOffice计算),它需要两个参数:

  • 一个整数
  • 一种"平均"数

和返回浮动。

在Python(I试图RandomArray和顽固)返回一系列的随机泊的数字。我真正想要的是百分比,这一事件将发生的(这是一个恒定的数目及列有每次不同的号码-那么这一平均?).

例如:

print poisson(2.6,6)

返回 [1 3 3 0 1 3] (每次我运行了它,它是不同的)。

我从计算/excel是3.19(POISSON(6,2.16,0)*100).

我使用的python泊错(没有双关语!) 或者我是不是错过什么?

有帮助吗?

解决方案

它是很容易做到通过,但你可以溢出这样做的方式。你可以做到的指数和因素在一个循环避免的溢出:

def poisson_probability(actual, mean):
    # naive:   math.exp(-mean) * mean**actual / factorial(actual)

    # iterative, to keep the components from getting too large or small:
    p = math.exp(-mean)
    for i in xrange(actual):
        p *= mean
        p /= i+1
    return p

其他提示

scipy 具有你想要什么

>>> scipy.stats.distributions
<module 'scipy.stats.distributions' from '/home/coventry/lib/python2.5/site-packages/scipy/stats/distributions.pyc'>
>>> scipy.stats.distributions.poisson.pmf(6, 2.6)
array(0.031867055625524499)

值得注意的是,它很容易计算的方面, .

这页 解释了为什么你会得到一个数组,并意义的数字,至少。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top