AttributeError: 'module' object has no attribute 'percentile'
Solution 1
The percentile
function was added in version 1.5.x. You will need to upgrade to at least that version.
Did you try:
sudo pip install numpy==1.7.1 --upgrade
To check which version you are running, start the python console and run:
>>> import numpy
>>> print numpy.__version__
You can also do:
sudo pip freeze | grep 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
Solution 2
Please upgrade your numpy package
pip install --upgrade numpy==1.19.1
or
sudo pip install --upgrade numpy==1.19.1
Related videos on Youtube
mongotop
BY DAY: Data Engineer. BY NIGHT: I like to hit the gym for a bit and cook some nice traditional Moroccan food. FOR FUN: camping during the weekend, watching movies in the theater and reading outdoors.
Updated on June 04, 2022Comments
-
mongotop over 1 year
I use this function to calculate percentile from here:
import numpy as np a = [12, 3, 45, 0, 45, 47, 109, 1, 0, 3] np.percentile(a, 25)
But I get this error :
AttributeError: 'module' object has no attribute 'percentile'
I also tried
import numpy.percentile as np
but it didn't I got the same error.
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.my ubuntu version 9.10
my python version is : 2.6.4
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
but when I tried to find
0.5 percentile
manually I found5
Can anyone help explain to me why this is happening in any of those cases?
-
mongotop over 10 yearsThanks alot for your replay and the link . No I didn't try
sudo pip install numpy==1.7.1 --upgrade
, but I just did, and i still get the same error message. -
mongotop over 10 yearsthe version is
1.3.0
, mean that the upgrade won't happened. -
Nathan Villaescusa over 10 yearsUninstall that version using
sudo apt-get remove python-numpy
-
mongotop over 10 yearsdone! do you recommend using
apt-get install python-numpy
to install numpy? -
Nathan Villaescusa over 10 yearsI would if you were using a recent version of Ubuntu, but you are using 9.10 which uses a very old (likely 1.3.0) version of numpy.
-
mongotop over 10 yearsany idea how to install a newer version?
-
Nathan Villaescusa over 10 yearsYou will need to install a newer version using pip. I would guess it is already installed and that you had two versions before.
-
mongotop over 10 years
-
mongotop over 10 yearsremoving and reinstaling numpy and I changed
import numpy.percentile
withfrom numpy import percentile
and that done the job