您好,欢迎来到五一七教育网。
搜索
您的当前位置:首页解决Error:AttributeError: module ‘numpy‘ has no attribute ‘complex‘

解决Error:AttributeError: module ‘numpy‘ has no attribute ‘complex‘

来源:五一七教育网

#  报错详情:

AttributeError: module 'numpy' has no attribute 'complex'. `np.complex` was a deprecated alias for the builtin `complex`. To avoid this error in existing code, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

解决方案1:降低NumPy版本

通过 `pip  show   numpy`得到numpy的版本为:
Name: numpy
Version: 1.24.4

我们需要卸载当前较新的NumPy版本,安装较老的NumPy版本。示例代码如下:

# 1. 卸载当前numpy库
pip uninstall numpy
# 2. 较老的NumPy版本
pip install numpy==1.21.6 -i https://pypi.tuna.tsinghua.edu.cn/simple

解决方案2:更改NumPy源码

通过报错提示找到出错源码的具体位置,通过修改源码来解决问题。

我们将此代码行进行修改,具体如下所示:

# wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex) # 修改前
wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex_) # 修改后


 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 517ttc.cn 版权所有 赣ICP备2024042791号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务