5

我正在使用scipy.ndimage.zoom,我收到了这个烦人的警告:

用户警告:从 scipy 0.13.0 开始,zoom() 的输出形状是用 round() 而不是 int() 计算的 - 对于这些输入,返回数组的大小已经改变。

我不确定我应该从中得到什么,我开始将它与 SciPy 1.0.0 一起使用,所以我不相信它真的会影响我。

我想称它为UserWarning有点可疑,因为它不是供用户使用的,但可能目标用户是导入库的开发人员。

我正在使用多处理,每个进程都会收到一个警告,更烦人。

有没有理智的方法让它静音?

4

2 回答 2

10

这比我想象的要容易,留下这个问题以备将来参考,以防有人需要。

import warnings
warnings.filterwarnings('ignore', '.*output shape of zoom.*')
于 2017-12-17T14:09:52.190 回答
2

您提出的解决方案对我不起作用。但有效的是:

  import warnings

  # other nice code

  with warnings.catch_warnings():
       warnings.simplefilter("ignore")
       x = scipy.ndimage.interpolation.zoom(...)
于 2018-10-31T13:12:47.000 回答