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

原因:

出现此问题的原因:

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 numpy
1.22.4

在这里插入图片描述


创作不易,观众老爷们请留步… 动起可爱的小手,点个赞再走呗 (๑◕ܫ←๑)
欢迎大家关注笔者,你的关注是我持续更博的最大动力


原创文章,转载告知,盗版必究



在这里插入图片描述


在这里插入图片描述
♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠

  • 90
    点赞
  • 112
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旋转的油纸伞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值