简体   繁体   中英

Error when importing numpy with a very simple script

I am receiving the following error when running a simple code which is the following:

import numpy as np

N = 10

diagonal = np.zeros(N) + 2

print diagonal

Error:

Traceback (most recent call last):
  File "diagonalmatrix.py", line 1, in <module>
    import numpy as np
  File "/Users/jamesmalone/Documents/Python/Coursework/numpy.py", line 5, in <module>
    diagonal = np.zeros(N) + 2
AttributeError: 'module' object has no attribute 'zeros'

There is a numpy.py file in your current working directory . You need to rename it with some other name and then try again. The thing is this file is getting imported rather than original numpy module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM