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

相关推荐
萧鼎4 分钟前
深入解析 Python 的 pytun 库:虚拟网络接口与隧道技术实战指南
服务器·网络·python
西猫雷婶20 分钟前
pytorch基本运算-分离计算
人工智能·pytorch·python·深度学习·神经网络·机器学习
数新网络23 分钟前
PyTorch
人工智能·pytorch·python
自信的小螺丝钉27 分钟前
【大模型手撕】pytorch实现LayerNorm, RMSNorm
人工智能·pytorch·python·归一化·rmsnorm·layernorm
深耕AI28 分钟前
PyTorch图像预处理:ToTensor()与Normalize()的本质区别
人工智能·pytorch·python
鲸屿1951 小时前
python之socket网络编程
开发语言·网络·python
里昆1 小时前
【AI】Tensorflow在jupyterlab中运行要注意的问题
人工智能·python·tensorflow
AI视觉网奇1 小时前
pycharm 最新版上一次编辑位置
python
2401_828890642 小时前
使用 BERT 实现意图理解和实体识别
人工智能·python·自然语言处理·bert·transformer
多恩Stone3 小时前
【3DV 进阶-2】Hunyuan3D2.1 训练代码详细理解下-数据读取流程
人工智能·python·算法·3d·aigc