AttributeError:模块“numpy”没有属性“complex”

Pal*_*ine 4 python numpy complex-numbers python-3.x

我正在尝试使用 numpy 将实数复数。我正在使用 numpy 版本1.24.3

这是代码:

import numpy as np
c=np.complex(1)
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

AttributeError: module 'numpy' has no attribute 'complex'.
Run Code Online (Sandbox Code Playgroud)

Pal*_*ine 5

np.complex是内置的已弃用的别名complex

np.complex可以使用:

complex(1)         #output (1+0j)

#or

np.complex128(1)   #output (1+0j)

#or

np.complex_(1)     #output (1+0j)

#or

np.cdouble(1)      #output (1+0j)
Run Code Online (Sandbox Code Playgroud)

链接到文档:https ://numpy.org/devdocs/release/1.20.0-notes.html#deprecations