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

相关推荐
掘金-我是哪吒26 分钟前
分布式微服务系统架构第132集:Python大模型,fastapi项目-Jeskson文档-微服务分布式系统架构
分布式·python·微服务·架构·系统架构
xhdll1 小时前
egpo进行train_egpo训练时,keyvalueError:“replay_sequence_length“
python·egpo
Cchaofan2 小时前
lesson01-PyTorch初见(理论+代码实战)
人工智能·pytorch·python
网络小白不怕黑2 小时前
Python Socket编程:实现简单的客户端-服务器通信
服务器·网络·python
Ronin-Lotus2 小时前
程序代码篇---python获取http界面上按钮或者数据输入
python·http
不知道写什么的作者2 小时前
Flask快速入门和问答项目源码
后端·python·flask
孙胜完不了4 小时前
Day29
python
lkx097884 小时前
第四天的尝试
python
lcccyyy14 小时前
day 29
python
(・Д・)ノ5 小时前
python打卡day29
开发语言·python