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

相关推荐
万行18 小时前
差速两轮机器人位移与航向角增量计算
人工智能·python·算法·机器人
叫我:松哥18 小时前
基于Flask框架开发的二手房数据分析与推荐管理平台,集成大数据分析、机器学习预测和智能推荐技术
大数据·python·深度学习·机器学习·数据分析·flask
weixin_4404016919 小时前
Win11 系统 Anaconda 下载+conda命令+Jupyter Notebook+VS Code
ide·python·jupyter·conda
知乎的哥廷根数学学派19 小时前
基于卷积特征提取和液态神经网络的航空发动机剩余使用寿命预测算法(python)
人工智能·pytorch·python·深度学习·神经网络·算法
高洁0119 小时前
AIGC技术与进展(2)
人工智能·python·深度学习·机器学习·数据挖掘
2501_9421917719 小时前
基于Faster-RCNN_Res2Net-101_FPN_2x_COCO的交通手势识别模型训练与实现_1
python
期末考复习中,蓝桥杯都没时间学了19 小时前
python调用百度智能云API完成文本情感分析
开发语言·python
CCPC不拿奖不改名19 小时前
“Token→整数索引” 的完整实现步骤
人工智能·python·rnn·神经网络·自然语言处理·token·josn
阿杰 AJie19 小时前
Java Stream API详细用法
java·windows·python
蒜香拿铁19 小时前
【第五章】python判断语句if
java·服务器·python