gpt4 book ai didi

python - 为什么我没有看到 Numpy 的 DeprecationWarning?

转载 作者:太空狗 更新时间:2023-10-30 01:00:11 28 4
gpt4 key购买 nike

我最近在我的一台机器上更新了 Python 的 Numpy 包,显然我一直依赖 a deprecated feature of numpy现在有一段时间了:

>>> np.__version__
'1.10.4'
>>> a = np.ones(10, dtype=np.uint16)
>>> a /= 0.5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'H') according to the casting rule ''same_kind''

上述链接中的一位评论者指出:

Probably means you didn't see the deprecation warnings since forever ;)

...这是正确的,我没有。

但是为什么?我是如何设法错过弃用警告的?

the documentation一致,同样的代码在我以前的 numpy 版本中的工作方式不同:

>>> np.__version__
'1.9.2'
>>> a = np.ones(10, dtype=np.uint16)
>>> a /= 0.5
>>> a
array([2, 2, 2, 2, 2, 2, 2, 2, 2, 2], dtype=uint16)

...但是这不应该触发警告吗?我是否误解了 numpy 如何处理弃用警告? 我如何确定我没有遗漏其他弃用警告

我的python环境:

Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32

最佳答案

弃用警告是 ignored by default .您需要通过使用 -Wd flag 运行 Python 来启用它们:

python -Wd my_source_file.py

或者通过安装一个新的警告过滤器规范来覆盖忽略 DeprecationWarning 的规范:

import warnings

# Print any warning the first time a given source line issues them,
# overriding built-in filters that ignore some warning types.
warnings.filterwarnings("default")

关于python - 为什么我没有看到 Numpy 的 DeprecationWarning?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37356814/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com