numpy 1.24.3调用np.complex报AttributeError问题求助
解决numpy 1.24.3中
np.complex报错的问题 numpy 1.24.3已移除np.complex API,该接口在1.20及以上版本就已被标记为弃用,可通过以下几种方式替代:
使用Python内置
complex()函数:import numpy as np c = complex(1) # 得到复数(1+0j)若需要numpy标量类型的复数,可结合
np.array指定 dtype:c = np.array(1, dtype=np.complex128)直接使用numpy的复数类型构造函数:
c = np.complex128(1)批量转换实数数组为复数数组:
real_array = np.array([1, 3, 5]) complex_array = np.asarray(real_array, dtype=np.complex128)
内容的提问来源于stack exchange,提问作者Talha Tayyab
相关产品推荐
相关产品推荐

