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
相关推荐
Xiu Yan5 天前
Python 数据分析:Pandas DataFrame 零基础入门教程
python·jupyter·pycharm·numpy·pandas
醇氧5 天前
Git 合并冲突与`__pycache__` 的恩怨情仇
python·numpy·fastapi
Xiu Yan6 天前
Python 数据分析:Pandas Series 零基础入门教程
python·jupyter·pycharm·numpy·pandas
lpfasd1238 天前
配置文件格式对比 与 AI Coding 的选择逻辑
python·flask·numpy
jzshmyt8 天前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy
搞AI的金鱼9 天前
Numpy
numpy
典典分享指南9 天前
用飞书 Wiki 搭内容作战室:从零搭建团队内容协作中枢
django·flask·numpy·pyqt
梦帮科技11 天前
从提示词到可复现音乐工作流:RNOISE 2.0 的 Prompt Engineering 架构
人工智能·python·mysql·ci/cd·架构·node.js·numpy
飞Link11 天前
【Numpy】 第三部分:矩阵运算与线性代数(计算篇)
python·numpy
kyrie_sakura12 天前
python学习笔记15 -- Anaconda,Jupyter,numpy
python·学习·jupyter·numpy