Importing Tester requires importing all of UnitTest which is not a AttributeError: module 'numpy' has no attribute 'bool'.
根据引用[1]中提到的错误信息,可以看出是因为numpy模块中没有名为bool的属性导致的。可能是因为numpy版本更新后,bool属性被移除或更改了名称。解决此问题的方法是使用numpy中的其他属性或方法来代替bool属性。例如,可以使用numpy中的bool_属性来代替bool属性。具体代码如下所示:
import numpy as np
import pandas 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 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:
import numpy.matlib
Then, you can use the matlib module as follows:
import numpy as np
matrix = np.matlib.ones((3, 3))
print(matrix)
This will create a 3x3 matrix of ones using the matlib module in NumPy.
相关推荐
















