【发布时间】:2013-04-08 07:14:55
【问题描述】:
我用这个函数计算here的百分位数:
import numpy as np
a = [12, 3, 45, 0, 45, 47, 109, 1, 0, 3]
np.percentile(a, 25)
但我收到此错误:
AttributeError: 'module' object has no attribute 'percentile'
我也试过
import numpy.percentile as np
但我没有得到同样的错误。
我的 numpy 版本是 1.3.0 我尝试升级但似乎不会使用:[sudo pip install --upgrade scipy][2] 但我发现没有升级。
我的 ubuntu 版本 9.10
我的python版本是:2.6.4
我也尝试绕过 numpy.percentile 模块,我发现了这个here:
>>> def percentile(N, P):
... n = int(round(P * len(N) + 0.5))
... if n > 1:
... return N[n-2]
... else:
... return 0
...
>>> a = [1, 23, 5, 45, 676, 2, 0, 4,3]
>>> a = sorted(a)
>>> a
[0, 1, 2, 3, 5, 4, 23, 45, 676]
#When I call the function using
>>> percentile(a,0.5)
3
但是当我尝试手动查找0.5 percentile 时,我找到了5
谁能帮我解释一下为什么在这些情况下会发生这种情况?
【问题讨论】:
标签: python numpy percentile