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

成功解决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

或者用pip安装也可以。

解决方案二:

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

import numpy as np

# Instead of numpy's float alias
x = np.float(10)

# Use the built-in float
x = float(10)

如:

np.float = float
np.int = int
np.object = object
np.bool = bool

或者

np.float = np.float64

猜你喜欢

转载自blog.csdn.net/qq_45934285/article/details/131120167
今日推荐