弃用警告:`np.bool`

Ahm*_*lla 10 python boolean numpy

我是使用 Spyder 的 Python 新手。我编写了以下代码:

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'][:]
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我不断收到以下错误,但我不确定为什么(我不知道 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
Run Code Online (Sandbox Code Playgroud)

jmd*_*_dk 12

这是无害的警告。如果你能忍受它,就别管它了。

出现这种情况是因为 NumPy 包最近弃用了它,numpy.bool转而使用标准 Python bool(或者尴尬的numpy.bool_),如警告消息中链接的文档页面所述。

如果你不能忍受这个警告,我建议你尝试更新spacepy。您还可以在项目中明确地消除警告。


luk*_*ell 7

正如其他答案所指出的,这是一个警告,通常不会影响任何事情。以下代码可用于选择性地静音此特定的DeprecationWarning

from warnings import filterwarnings
filterwarnings(action='ignore', category=DeprecationWarning, message='`np.bool` is a deprecated alias')
Run Code Online (Sandbox Code Playgroud)