问题描述
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
或者用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)
如:文章来源:https://www.toymoban.com/news/detail-558849.html
np.float = float
np.int = int
np.object = object
np.bool = bool
或者文章来源地址https://www.toymoban.com/news/detail-558849.html
np.float = np.float64
到了这里,关于成功解决AttributeError: module ‘numpy‘ has no attribute ‘float‘.的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!