您现在的位置是:首页 > 技术教程 正文

成功解决AttributeError: module ‘numpy‘ has no attribute ‘float‘.

admin 阅读: 2024-03-23
后台-插件-广告管理-内容页头部广告(手机)

成功解决AttributeError: module 'numpy' has no attribute 'float'.

  • 问题描述
  • 解决方案一:
  • 解决方案二:

问题描述

AttributeError: module ‘numpy’ has no attribute ‘float’.
np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
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

解决方案一:

不用改代码的,就重新安装numpy
出现这个问题是因为np.float从1.24起被删除。所用的代码是依赖于旧版本的Numpy。您可以将你的Numpy版本降级到1.23.5.

conda install numpy==1.23.5
  • 1

或者用pip安装也可以。

解决方案二:

将代码中的np.float改为float,如下:
在大多数情况下,只需将 numpy 的别名替换为内置的 Python 类型就可以解决问题。bool、str、int等也类似。

import numpy as np # Instead of numpy's float alias x = np.float(10) # Use the built-in float x = float(10)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

如:

np.float = float np.int = int np.object = object np.bool = bool
  • 1
  • 2
  • 3
  • 4

或者

np.float = np.float64
  • 1
标签:
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

在线投稿:投稿 站长QQ:1888636

后台-插件-广告管理-内容页尾部广告(手机)
关注我们

扫一扫关注我们,了解最新精彩内容

搜索