如何将所有属性导入 numpy 模块?

how to import all attribute to numpy module?

我在使用此命令时遇到问题(ubuntu 18.04) :

mpiexec -np 1 python3 hello-Project.py

代码示例是:

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)

相对输出为:

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

我正在使用 dir 命令查看 py 脚本中的 numpy 属性,但不收取属性。 但是在命令行 python shell 工作,我也是 jupyterlab。

如何解决?

import numpy as np
...
np = ops.getNP()
# any subsequent references to "np" will find the integer, not the numpy module

在将 ops.getNP()(整数)的结果分配给名称 np 时,您正在隐藏对 numpynp 引用。

在导入 numpy 时删除 as np 或为 ops.getNP()

返回的整数选择另一个名称