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

相关推荐
abc123456sdggfd5 分钟前
c++如何读取并展示ZIP压缩包内的目录结构树_minizip集成【附源码】
jvm·数据库·python
itzixiao7 分钟前
L1-055 谁是赢家(10 分)[java][python]
java·python·算法
2301_814809868 分钟前
如何配置Oracle UTL_FILE目录_CREATE DIRECTORY语法与权限分配.txt
jvm·数据库·python
遇见火星11 分钟前
Firewalld 防火墙实战指南 + TCPWrapper 七层访问控制
开发语言·windows·python
dddaidai12313 分钟前
LlamaIndex
python·ai·rag·llamaindex
m0_7349497916 分钟前
golang如何使用expvar暴露运行时指标_golang expvar运行时指标暴露步骤
jvm·数据库·python
qq_4138474021 分钟前
开发者工具怎么看HTML_Elements面板使用指南【操作】
jvm·数据库·python
zh路西法21 分钟前
【ROS2多激光雷达融合】基于ROS2的双2D激光雷达点云融合与遮挡剔除方案
c++·python·机器人
qq_3729069321 分钟前
mysql如何设置密码过期策略_mysql default_password_lifetime
jvm·数据库·python
七颗糖很甜24 分钟前
开源雷达NEXRAD Level 3 数据完整获取与 Python 处理教程
大数据·python·算法