问题
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