简体   繁体   English

使用 Python 中 numpy package 中的数组方法

[英]Using the array method from the numpy package in Python

I want to use the array method from the numpy package, but I get an attribute error and it says that there is no method called array.我想使用 numpy package 中的数组方法,但我得到一个属性错误,它说没有称为数组的方法。 what is the problem?问题是什么?

import numpy as np

x = [2, 3, 4, 6, 7, 9]
y = np.array(x)
print(y)

AttributeError: partially initialized module 'numpy' has no attribute 'array' (most likely due to a circular import) AttributeError:部分初始化的模块“numpy”没有属性“array”(很可能是由于循环导入)

A way to debug this behaviour is to print the origin of the file that you are importing:调试此行为的一种方法是打印您正在导入的文件的来源:

import numpy as np
print(np.__file__)

This will return the path of your imported package and you could realise that it is not the one you intended to import.这将返回您导入的 package 的路径,您可能会意识到它不是您要导入的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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