Python 如何将所有属性导入numpy模块?
我在使用这个命令时遇到了问题(ubuntu 18.04): 代码示例为:Python 如何将所有属性导入numpy模块?,python,python-3.x,numpy,ubuntu-18.04,jupyter-lab,Python,Python 3.x,Numpy,Ubuntu 18.04,Jupyter Lab,我在使用这个命令时遇到了问题(ubuntu 18.04): 代码示例为: import openseespy.opensees as ops import numpy as np import time import sys print (sys.version) print(np.__version__) pid = ops.getPID() np = ops.getNP() #print(dir(numpy)) prove = np.array([1, 2, 3]) nodi = nump
import openseespy.opensees as ops
import numpy as np
import time
import sys
print (sys.version)
print(np.__version__)
pid = ops.getPID()
np = ops.getNP()
#print(dir(numpy))
prove = np.array([1, 2, 3])
nodi = numpy.array([[99,0.0,0.0,0.0]])
print(nodi,prove)
print('Hello World Process:', pid)
if pid == 0:
print('Total number of processes:', np)
相对的autput是:
3.6.8 (default, Oct 7 2019, 12:59:55)
[GCC 8.3.0]
1.17.4
Traceback (most recent call last):
File "hello-Project.py", line 11, in <module>
prove = np.array([1, 2, 3])
AttributeError: 'int' object has no attribute 'array'
Process 0 Terminating
3.6.8(默认,2019年10月7日12:59:55)
[GCC 8.3.0]
1.17.4
回溯(最近一次呼叫最后一次):
文件“hello Project.py”,第11行,在
prove=np.array([1,2,3])
AttributeError:“int”对象没有属性“array”
进程0正在终止
我使用dir命令查看py脚本中的numpy属性和dont charge属性。
但在命令行中,pythonshell可以工作,我也可以使用jupyterlab
如何解决这个问题
import numpy as np
...
np = ops.getNP()
# any subsequent references to "np" will find the integer, not the numpy module
将ops.getNP()
(是一个整数)的结果分配给名称np
时,您正在隐藏对numpy
的引用
导入numpy
时将作为np
删除,或者为ops.getNP()返回的整数选择另一个名称
将ops.getNP()
(是一个整数)的结果分配给名称np
时,您正在隐藏对numpy
的引用
导入numpy
时将作为np
删除,或者为ops.getNP()返回的整数选择另一个名称
import numpy as np
...
np = ops.getNP()
# any subsequent references to "np" will find the integer, not the numpy module