弃用警告:`np.bool`
DeprecationWarning: `np.bool`
我是 Python 使用 Spyder 的新手。我写了下面的代码:
import os
import numpy as np
os.environ["CDF_LIB"] = "D:\Anaconda\Lib"
from spacepy import pycdf
cdf = pycdf.CDF('Sample.cdf')
print(cdf) # Print the titles of the CDF file
Diff_en=cdf['diff'][:]
出于某种原因,我不断收到以下错误,我不确定原因(我不知道 bool 是什么)。感谢任何帮助:
Diff_en=cdf['diff'][:]
D:\Anaconda\lib\site-packages\spacepy\pycdf\__init__.py:3957: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, 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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
这是一个无害的警告。如果你能忍受它,就随它去吧。
它的出现是因为 NumPy 包 recently deprecated 它的 numpy.bool
支持标准 Python bool
(或者笨拙的 numpy.bool_
),如警告消息中链接的文档页面所述。
如果你不能忍受警告,我建议你尝试更新 spacepy。您也可以从您的项目中 silence the warning explicitly。
正如其他回答所指出的那样,这是一个警告,通常不会影响任何事情。
以下代码可用于有选择地静音此特定 DeprecationWarning
from warnings import filterwarnings
filterwarnings(action='ignore', category=DeprecationWarning, message='`np.bool` is a deprecated alias')
我是 Python 使用 Spyder 的新手。我写了下面的代码:
import os
import numpy as np
os.environ["CDF_LIB"] = "D:\Anaconda\Lib"
from spacepy import pycdf
cdf = pycdf.CDF('Sample.cdf')
print(cdf) # Print the titles of the CDF file
Diff_en=cdf['diff'][:]
出于某种原因,我不断收到以下错误,我不确定原因(我不知道 bool 是什么)。感谢任何帮助:
Diff_en=cdf['diff'][:]
D:\Anaconda\lib\site-packages\spacepy\pycdf\__init__.py:3957: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, 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.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
这是一个无害的警告。如果你能忍受它,就随它去吧。
它的出现是因为 NumPy 包 recently deprecated 它的 numpy.bool
支持标准 Python bool
(或者笨拙的 numpy.bool_
),如警告消息中链接的文档页面所述。
如果你不能忍受警告,我建议你尝试更新 spacepy。您也可以从您的项目中 silence the warning explicitly。
正如其他回答所指出的那样,这是一个警告,通常不会影响任何事情。
以下代码可用于有选择地静音此特定 DeprecationWarning
from warnings import filterwarnings
filterwarnings(action='ignore', category=DeprecationWarning, message='`np.bool` is a deprecated alias')