运行以下简单代码时收到以下错误:
import numpy as np
N = 10
diagonal = np.zeros(N) + 2
print diagonal
错误:
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'
答案 0 :(得分:2)
当前工作目录中有numpy.py
个文件。您需要使用其他名称重命名,然后重试。问题是这个文件是导入而不是原始的numpy
模块。