gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:08:06 25 4
gpt4 key购买 nike

我在使用这个命令时遇到了问题(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.

在导入 numpy 时删除 as np 或为 ops.getNP() 返回的整数选择另一个名称

关于python - 如何将所有属性导入 numpy 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58918270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com