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
相关推荐
弱冠少年15 小时前
websockets库使用(基于Python)
开发语言·python·numpy
A_lvvx2 天前
07_矩形圆形绘制
开发语言·python·numpy
星霜旅人3 天前
Python数据分析篇--NumPy--进阶
python·数据分析·numpy
敲代码不忘补水5 天前
Python NumPy 数据分析:处理复杂数据的高效方法
python·数据分析·numpy
Thetoicxdude5 天前
[Day 80] 區塊鏈與人工智能的聯動應用:理論、技術與實踐
人工智能·web3·numpy
Thetoicxdude6 天前
[Day 82] 區塊鏈與人工智能的聯動應用:理論、技術與實踐
人工智能·web3·numpy
凭栏落花侧6 天前
数据预处理:数据挖掘的第一步
人工智能·python·数据挖掘·conda·numpy·pandas·pip
cndes7 天前
Numpy 和 Pandas的区别与高效协同
numpy·pandas
跟德姆(dom)一起学AI7 天前
0基础跟德姆(dom)一起学AI 数据处理和统计分析08-日期类型处理,Matplotlib介绍
开发语言·人工智能·python·信息可视化·numpy·matplotlib
deephub8 天前
8种数值变量的特征工程技术:利用Sklearn、Numpy和Python将数值转化为预测模型的有效特征
人工智能·python·机器学习·numpy·sklearn·特征工程