Python 使用 numpy 'module' 对象没有属性 'array'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36530726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using numpy 'module' object has no attribute 'array'
提问by The Nightman
I am just trying to convert a list to a 1D array like so:
我只是想将列表转换为一维数组,如下所示:
import numpy as np
print np.array([2, 3, 4])
But I get the following error:
但我收到以下错误:
Traceback (most recent call last):
File "numpy.py", line 11, in <module>
test_run()
File "numpy.py", line 8, in test_run
print np.array([2, 3, 4])
AttributeError: 'module' object has no attribute 'array'
I tried reinstalling numpy because that seems to have worked for others, but this does not fix the problem.
我尝试重新安装 numpy,因为这似乎对其他人有用,但这并不能解决问题。
回答by timgeb
You are most likely having a file called numpy.py in your working directory which shadows the real numpy module. Rename that file and remove its numpy.pyc file.
您的工作目录中很可能有一个名为 numpy.py 的文件,它隐藏了真正的 numpy 模块。重命名该文件并删除其 numpy.pyc 文件。