使用 numpy 'module' 对象没有属性 'array' [英] Using numpy 'module' object has no attribute 'array'

查看:51
本文介绍了使用 numpy 'module' 对象没有属性 'array'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想像这样将列表转换为一维数组:

I am just trying to convert a list to a 1D array like so:

import numpy as np

print np.array([2, 3, 4])

但我收到以下错误:

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'

我尝试重新安装 numpy,因为这似乎对其他人有效,但这并不能解决问题.

I tried reinstalling numpy because that seems to have worked for others, but this does not fix the problem.

推荐答案

您的工作目录中很可能有一个名为 numpy.py 的文件,它隐藏了真正的 numpy 模块.重命名该文件并删除其 numpy.pyc 文件.

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 'module' 对象没有属性 'array'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆