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

相关推荐
workflower7 小时前
时序数据获取事件
开发语言·人工智能·python·深度学习·机器学习·结对编程
C++业余爱好者8 小时前
Java 提供了8种基本数据类型及封装类型介绍
java·开发语言·python
AI Echoes9 小时前
构建一个LangChain RAG应用
数据库·python·langchain·prompt·agent
派大鑫wink9 小时前
从零到精通:Python 系统学习指南(附实战与资源)
开发语言·python
c骑着乌龟追兔子9 小时前
Day 38 官方文档的阅读
python
羸弱的穷酸书生10 小时前
国网 i1协议 python实现
开发语言·python
weixin_4620223510 小时前
RAW-Adapter: Adapting Pre-trained Visual Model to Camera RAW Images
python·计算机视觉
电子硬件笔记10 小时前
Python语言编程导论第三章 编写程序
开发语言·python·编辑器
布谷歌10 小时前
在java中实现c#的int.TryParse方法
java·开发语言·python·c#