赞
踩
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)
如:
np.float = float
np.int = int
np.object = object
np.bool = bool
或者
np.float = np.float64
出现此问题的原因:
np.float is a deprecated alias for the builtin float. To silence this warning, 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. Deprecated in NumPy 1.20; for more details and guidance: numpy.org/devdocs/release/1.20.0-notes.html#deprecations
np.float 是内置 float 的已弃用别名。要消除此警告,请单独使用 float。这样做不会改变任何行为并且是安全的。如果您特别想要 numpy 标量类型,请在此处使用 np.float64。在 NumPy 1.20 中已弃用;有关更多详细信息和指导:numpy.org/devdocs/release/1.20.0-notes.html#deprecations
This was the standard python float object, but as mentioned, numpy.float has been deprecated… and removed in 1.24. You can either use float or pick one of the np.float32, np.float64, np.float128 (is that all of them?!). That second option seems reasonable to me.
这是标准的 python float 对象,但正如前面提到的,numpy.float 已被弃用…并在 1.24 中删除。您可以使用 float 或选择 np.float32、np.float64、np.float128 之一(是全部吗?!)。第二种选择对我来说似乎是合理的。
As np.float is deprecated and in my code base, np.float is in multiple places, For now I downgraded Numpy version. This worked for me: pip install numpy1.22.4
由于 np.float 已被弃用,并且在我的代码库中,np.float 存在于多个位置,现在我降级了 Numpy 版本。这对我有用: pip install numpy1.22.4
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。