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

相关推荐
我是坏垠40 分钟前
Crypto、Cipher与Password:Java加密开发的三个核心概念
java·开发语言·python
测试秃头怪2 小时前
如何评估自动化测试脚本的编写时间和维护工作量?
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
姚青&2 小时前
测试左移体系
python·自动化
技术民工之路2 小时前
Python Socket编程零基础实战教程(TCP/UDP通信完整版)
python·tcp/ip·udp
EW Frontier2 小时前
三级跳突破864维动作空间——QMIX-Hierarchical多无人机协同通信方法全解析【附python代码】
开发语言·python·无人机·强化学习·通信资源分配
中微极客3 小时前
TensorFlow模型量化实战:从精度到延迟的优化指南
人工智能·python·tensorflow
仙人球部落5 小时前
-python-LangGraph框架(3-31-LangGraph 「合并式状态管理」的原理与实践)
开发语言·javascript·python
蜡笔削薪5 小时前
财联支付异地拓展商户的区域限制是否符合监管规定?
大数据·python
印度神油95 小时前
Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
windows·python·ci/cd