Finding location in code for numpy RuntimeWarning

删除回忆录丶 提交于 2021-02-07 14:55:21

问题


I am getting warnings like these when running numpy on reasonably large pipeline.

RuntimeWarning: invalid value encountered in true_divide

RuntimeWarning: invalid value encountered in greater

How do I find where they are occurring in the code besides writing dozens of print statements?

Python 2.7 and numpy 1.8.1


回答1:


One way is to convert the warnings to errors:

import warnings
warnings.simplefilter('error', RuntimeWarning)

Then the traceback will tell you where the error occurred.



来源:https://stackoverflow.com/questions/28546563/finding-location-in-code-for-numpy-runtimewarning

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!