解决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影响其他库,我选择了第二种方法,结果如下可以正常运行

相关推荐
hhhjllhj18 小时前
如何用关键词优化报表提升网站流量?
python·搜索引擎·facebook
明月(Alioo)18 小时前
Python 并发编程详解 - Java 开发者视角
java·开发语言·python
跟着珅聪学java18 小时前
编写高质量 CSS 样式完全指南
人工智能·python·tensorflow
进击的小头18 小时前
第18篇:PID参数整定与裕度优化的现场调试实战
python·算法
飞Link19 小时前
LangChain 核心链式架构演进史:从顺序链到企业级路由兜底实战
python·架构·langchain
啥咕啦呛19 小时前
java打卡学习3:ArrayList扩容机制
java·python·学习
编程之升级打怪19 小时前
用排他锁来实现Python语言的变量值更新
开发语言·python
打乒乓球只会抽19 小时前
【无标题】
python
路小雨~19 小时前
Django 学习笔记:从入门到项目开发的完整梳理
笔记·python·学习·django
Yana.nice19 小时前
Ansible 常用模块
网络·python·ansible