使用非常简单的脚本导入numpy时出错

时间:2014-12-29 15:13:38

标签: python

运行以下简单代码时收到以下错误:

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'

1 个答案:

答案 0 :(得分:2)

当前工作目录中有numpy.py个文件。您需要使用其他名称重命名,然后重试。问题是这个文件是导入而不是原始的numpy模块。