AttributeError:“模块"对象没有属性“百分位数" [英] AttributeError: 'module' object has no attribute 'percentile'

查看:107
本文介绍了AttributeError:“模块"对象没有属性“百分位数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此函数从此处计算百分位:

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

但是我没有遇到同样的错误.

but it didn't I got the same error.

我的numpy版本是1.3.0,我尝试升级,但好像不使用它:[sudo pip install --upgrade scipy][2],但我发现没有升级.

my numpy version is 1.3.0 I tried to upgrade but it seems like it won't I used : [sudo pip install --upgrade scipy][2] but I found that there's no upgrade.

我的ubuntu版本9.10

my ubuntu version 9.10

我的python版本是:2.6.4

my python version is : 2.6.4

我也尝试绕过numpy.percentile模块,我发现了这个

i also tried to go arround the numpy.percentile module and I found this 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

but when I tried to find 0.5 percentile manually I found 5

有人可以帮我解释一下为什么在任何情况下都会发生这种情况吗?

Can anyone help explain to me why this is happening in any of those cases?

推荐答案

percentile函数已添加到

The percentile function was added in version 1.5.x. You will need to upgrade to at least that version.

您尝试过吗:

sudo pip install numpy==1.7.1 --upgrade

要检查您正在运行的版本,请启动python控制台并运行:

To check which version you are running, start the python console and run:

>>> import numpy
>>> print numpy.__version__

您也可以这样做:

sudo pip freeze | grep numpy

Ubuntu 9.10 numpy软件包使用版本1.3.03 .安装1.7.0 vai pip版本可能成功,但是您的计算机默认使用python-numpy版本.您可以通过运行以下命令删除

The Ubuntu 9.10 numpy package uses version 1.3.03. It is likely that installing version 1.7.0 vai pip was successful, but your machine is defaulting to the python-numpy version instead. You can remove by running:

sudo apt-get remove python-numpy

这篇关于AttributeError:“模块"对象没有属性“百分位数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆