# 报错详情:
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_) # 修改后