0

I quite begginer with Python and have actually a problem with numpy. When I try to import seaborn (chart visualisation) or to do a kmeans with sklearn, I have a message of error :

"AttributeError: module 'numpy' has no attribute 'round'"

I don't really understand the problem.

My numpy package is version 1.23.4 and I already tried to update the package and pip but the problem keep. Does some can help me please ? Many thankss

3
  • 2
    Any chance you wrote a python script called "numpy.py"? It may be that something else with the same name is imported. You could import numpy and then print(numpy.__file__) to see where the .py file is. And print(numpy.__version__) to see its version. Commented Nov 3, 2022 at 16:24
  • @tdelaney has an important point that beginners overlook. Please check that before moving forward Commented Nov 3, 2022 at 16:41
  • Please provide enough code so others can better understand or reproduce the problem. Commented Nov 3, 2022 at 19:25

2 Answers 2

0

If you are performing the rounding yourself:

There is no numpy round function but there is a round_ function.


np.round(arr) #does not exist
np.round_(arr) #does exist

If you are NOT:

Please check that you have NOT overwritten numpy.py somewhere on accident

Sign up to request clarification or add additional context in comments.

3 Comments

At least on my numpy 1.21.5, round exists as an alias to round_.
Fair point and good comment - there's also an around method that seems to do the same thing. Interesting naming on their end.
np.round(data) # do work. I show you the problem : import seaborn as sns return : AttributeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_33196\2215191008.py in <cell line: 6>() import seaborn as sns c:\...\Python310\lib\site-packages\seaborn_init_.py in <module> ---> 31 from scipy.stats import gaussian_kde ... --> 489 x = np.round(x).astype(np.intp, copy=False) 490 491 if x.ndim < 3: AttributeError: module 'numpy' has no attribute 'round'
0

Try reinstalling numpy as:

if on anaconda environment: conda install numpy, else using PIP: pip install numpy

If the installation fails to solve the problem:

Uninstall the existing numpy:

  • conda remove numpy then conda install numpy
  • pip uninstall numpy then pip install numpy

Above solved my problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.