You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 20:54:54