AttributeError: 模块 ‘numpy’ 没有 ‘complex’ 属性

huangapple go评论216阅读模式
英文:

AttributeError: module 'numpy' has no attribute 'complex'

问题

我正在尝试使用numpy创建一个复数。我正在使用numpy版本1.24.3

以下是代码:

import numpy as np
c = np.complex(1)

然而,我收到以下错误:

AttributeError: module 'numpy' has no attribute 'complex'.
英文:

I am trying to make a real number complex using numpy. I am using numpy version 1.24.3

Here is the code:

import numpy as np
c=np.complex(1)

However, I get this error:

AttributeError: module 'numpy' has no attribute 'complex'.

答案1

得分: 4

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

你可以使用以下之一来替代 np.complex

  • complex(1) #输出 (1+0j)

或者

  • np.complex128(1) #输出 (1+0j)

或者

  • np.complex_(1) #输出 (1+0j)

或者

  • np.cdouble(1) #输出 (1+0j)

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

英文:

np.complex was a deprecated alias for the builtin complex.

Instead of np.complex you can use:

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)

Link to doc: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

huangapple
  • 本文由 发表于 2023年5月25日 17:14:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76330655.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定