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

相关推荐
2401_8685347826 分钟前
55 个热门网络面试问题及答案
网络·python
aifannihao32 分钟前
ON CONFLICT 冲突后返回空:sqlite3 实测 get-or-create
数据库·python·postgresql·sqlite3·标准库
用户0332126663671 小时前
使用 Python 合并 Excel 工作簿
python
__underline__1 小时前
冷门Python知识点008篇:__int__、__index__与__float__,Python数值转换的真实回退顺序?
后端·python
FriendshipT1 小时前
YOLOE Docker 部署实战:三模式推理、掩码输出与跨图视觉的完整实现
运维·人工智能·python·深度学习·docker·容器
tryCbest1 小时前
Python 爬虫扩展篇(一):APP 抓包与 JS 逆向入门——从看见流量到读懂签名
javascript·爬虫·python
月光船幽幽2 小时前
基线漂移破解:微服务测试一致性方案
python·科技·微服务
yiangL_2 小时前
课后作业7:自动轨迹绘制
python
Wellijohn2 小时前
async 里混进一行同步代码:事件循环卡死 4 秒,我写了个探针把它抓出来
后端·python·性能优化
JonaHu3 小时前
GPT Image 2.6 电商换背景如何公平对比:同源候选、匿名评审与返工统计
图像处理·人工智能·python·aigc