在Excel (或OpenOffice Calc)中使用泊松函数时,它有两个参数:
并返回一个浮点数。
在Python语言中(我尝试过RandomArray和NumPy),它返回一个随机泊松数数组。我真正想要的是这个事件发生的百分比(它是一个常量,数组每次都有不同的数字-所以它是一个平均值吗?)
例如:
print poisson(2.6,6)返回[1 3 3 0 1 3] (每次我运行它,它都是不同的)。
我从calc/excel得到的数字是3.19 (POISSON(6,2.16,0)*100)。
我是不是用错了蟒蛇的毒液(没有双关语!)还是我错过了什么?
发布于 2008-11-11 13:24:41
手工操作很容易,但是您可以通过这种方式进行溢出操作。您可以在循环中执行指数和阶乘,以避免溢出:
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发布于 2008-11-11 13:17:55
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)值得注意的是,手工计算非常容易,too。
发布于 2008-11-11 13:12:41
This page解释了获取数组的原因,以及数组中数字的含义。
https://stackoverflow.com/questions/280797
复制相似问题