报错line 305, in __getattr__ raise AttributeError(__former_attrs__[attr]) 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. Did you mean: 'cfloat'?
时间: 2023-12-03 17:45:39 浏览: 528
这是因为你的代码中使用了 `np.float`,但该别名已经在 NumPy 1.20 版本中被弃用。为了避免这个错误,你可以将代码中所有的 `np.float` 替换为 `float`。如果你确实需要使用 NumPy 的浮点数类型,可以使用 `np.float64` 来代替。例如:
```
import numpy as np
# 使用 float
x = float(1.0)
# 使用 np.float64
y = np.float64(1.0)
```
相关问题
AttributeError Traceback (most recent call last) Cell In[37], line 36 34 #%% 35 Pano_len = len(Pano_set_org) ---> 36 path_mat = np.zeros([Pano_len,Pano_len]).astype(np.bool) 37 for ind in list(Pano_set_org): 38 match_all_pd_start = match_all_pd_current[match_all_pd_current.pic_id1 == ind] File C:\Anaconda3\envs\pytorch\lib\site-packages\numpy\__init__.py:305, in __getattr__(attr) 300 warnings.warn( 301 f"In the future `np.{attr}` will be defined as the " 302 "corresponding NumPy scalar.", FutureWarning, stacklevel=2) 304 if attr in __former_attrs__: --> 305 raise AttributeError(__former_attrs__[attr]) 307 # Importing Tester requires importing all of UnitTest which is not a 308 # cheap import Since it is mainly used in test suits, we lazy import it 309 # here to save on the order of 10 ms of import time for most users 310 # 311 # The previous way Tester was imported also had a side effect of adding 312 # the full `numpy.testing` namespace 313 if attr == 'testing': AttributeError: module 'numpy' has no attribute 'bool'. `np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` 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
这个错误是因为你使用了已经被弃用的np.bool,你需要将其改为Python内置的bool类型。你可以将代码中的以下语句:
```
path_mat = np.zeros([Pano_len,Pano_len]).astype(np.bool)
```
改为:
```
path_mat = np.zeros([Pano_len,Pano_len], dtype=bool)
```
这样就可以避免这个错误了。
File "E:\Envs\tensorflow\lib\site-packages\tensorflow\python\framework\constant_op.py", line 29, in <module> from tensorflow.python.eager import execute File "E:\Envs\tensorflow\lib\site-packages\tensorflow\python\eager\execute.py", line 27, in <module> from tensorflow.python.framework import dtypes File "E:\Envs\tensorflow\lib\site-packages\tensorflow\python\framework\dtypes.py", line 585, in <module> np.object, File "E:\Envs\tensorflow\lib\site-packages\numpy\__init__.py", line 305, in __getattr__ raise AttributeError(__former_attrs__[attr])
这是一个错误提示,看起来是 TensorFlow 和 NumPy 之间的冲突。可能的解决方法是升级 TensorFlow 和 NumPy 到最新版本,或者检查是否有重复安装了 TensorFlow 和 NumPy。如果问题仍然存在,可以尝试卸载并重新安装 TensorFlow 和 NumPy。另外,也可以尝试使用其他的 Python 环境或虚拟环境来运行代码。
阅读全文