解决AttributeError: module ‘numpy‘ has no attribute ‘int‘.报错问题

报错内容:

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

`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.

The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:

https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

最近学习鸢尾花分类的案例,其中一步报错,如上所示

原因:

新的版本里面没有np.int了

解决办法:

1、降低版本:

复制代码
pip uninstall numpy

pip install numpy==1.19.0

2、修改源码:

复制代码
y=(iris['target']==2).astype(np.int)        #修改前
y=(iris['target']==2).astype(int)           #修改后

为了防止低版本的numpy影响其他库,我选择了第二种方法,结果如下可以正常运行

相关推荐
white-persist7 分钟前
MCP协议深度解析:AI时代的通用连接器
网络·人工智能·windows·爬虫·python·自动化
codists37 分钟前
2025年9月文章一览
python
语落心生40 分钟前
FastDeploy SD & Flux 扩散模型边缘端轻量化推理部署实现
python
java1234_小锋1 小时前
TensorFlow2 Python深度学习 - TensorFlow2框架入门 - 立即执行模式(Eager Execution)
python·深度学习·tensorflow·tensorflow2
王大傻09281 小时前
numpy -- 算术函数 reciprocal() 和 power() 简介
python·numpy
咕白m6251 小时前
Python 将 Excel 转换为图片:实现数据可视化
后端·python
深蓝电商API2 小时前
不止是 Python:聊聊 Node.js/Puppeteer 在爬虫领域的应用
爬虫·python·node.js
Autumn72992 小时前
【材料学python入门】conda、 jupyter、cpu、GPAW、wsl、ubuntu
python·jupyter·conda
K2I-2 小时前
UCI中Steel Plates Faults不平衡数据集处理
python
蓑笠翁0012 小时前
Django REST Framework 全面指南:从模型到完整API接口开发
后端·python·django