AttributeError: module ‘numpy‘ has no attribute ‘int‘.

问题描述

复现代码过程中遇到错误:AttributeError: module 'numpy' has no attribute 'int'.

错误代码行:

python 复制代码
self.sf = np.int(data['sf'][0,...].squeeze().cpu().numpy()) # scale factor

解决方案

这是因为在Numpy 1.2.0版本中就已经弃用了这个用法:np.int。先来看一下我的numpy版本:

  • 解决方案一(不推荐):

修改numpy版本,改为numpy==1.22.0

python 复制代码
pip install numpy==1.22.0
  • 解决方案二:

修改报错行代码,将来 np.int修改为 int

python 复制代码
self.sf = int(data['sf'][0,...].squeeze().cpu().numpy()) # scale factor
相关推荐
咚咚王者3 天前
人工智能之数据分析 numpy:第十三章 工具衔接与迁移
人工智能·数据分析·numpy
咚咚王者3 天前
人工智能之数据分析 numpy:第九章 数组运算(二)
人工智能·数据分析·numpy
咚咚王者4 天前
人工智能之数据分析 numpy:第十二章 数据持久化
人工智能·数据分析·numpy
咚咚王者6 天前
人工智能之数据分析 numpy:第十五章 项目实践
人工智能·数据分析·numpy
咚咚王者9 天前
人工智能之数据分析 numpy:第十章 副本视图
人工智能·数据分析·numpy
咚咚王者9 天前
人工智能之数据分析 numpy:第十一章 字符串与字节交换
人工智能·数据分析·numpy
AI小云11 天前
【数据操作与可视化】Pandas数据处理-Series数据结构
开发语言·数据结构·python·numpy·pandas
咚咚王者11 天前
人工智能之数据分析 numpy:第八章 数组广播
人工智能·数据分析·numpy
咚咚王者11 天前
人工智能之数据分析 numpy:第七章 数组迭代排序筛选
人工智能·数据分析·numpy