Importing Tester requires importing all of UnitTest which is not a AttributeError: module 'numpy' has no attribute 'bool'.
时间: 2023-12-09 10:36:57
浏览: 249
根据引用[1]中提到的错误信息,可以看出是因为[numpy](https://wenku.csdn.net/doc/6412b6ecbe7fbd1778d48761?spm=1055.2569.3001.10083)模块中没有名为bool的属性导致的。可能是因为numpy版本更新后,bool属性被移除或更改了名称。解决此问题的方法是使用numpy中的其他属性或方法来代替bool属性。例如,可以使用numpy中的bool_属性来代替bool属性。具体代码如下所示:
```[python](https://wenku.csdn.net/doc/6412b46ebe7fbd1778d3f92a?spm=1055.2569.3001.10083)
[import](https://wenku.csdn.net/doc/5cpc346q6x?spm=1055.2569.3001.10083) numpy as np
import [pandas](https://wenku.csdn.net/doc/6412b725be7fbd1778d4940f?spm=1055.2569.3001.10083) as pd
# 2. Importing dataset
dataset = pd.read_csv('Data.csv') # read csv file
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
# [replace](https://wenku.csdn.net/doc/6412b679be7fbd1778d46dbd?spm=1055.2569.3001.10083) bool with bool_
X = np.where(X == 'yes', 1, 0).astype(np.bool_)
相关问题
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)
这样就可以避免这个错误了。
AttributeError: module 'numpy' has no attribute 'matlib'
This error occurs when you try to use the matlib module in NumPy, but NumPy does not recognize it. The matlib module is a sub-module of NumPy that provides a matrix library that is similar to MATLAB's matrix library.
To fix this error, you can try importing the matlib module explicitly by adding the following line of code at the beginning of your script:
```python
import numpy.matlib
```
最低
0.47元/天
开通会员,查看完整答案
成为会员后, 你将解锁
下载资源随意下
优质VIP博文免费学
优质文库回答免费看
C知道免费提问
付费资源9折优惠