Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding location in code for numpy RuntimeWarning

Tags:

python

numpy

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

like image 688
Dave31415 Avatar asked Feb 16 '15 17:02

Dave31415


1 Answers

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.

like image 194
Warren Weckesser Avatar answered Nov 15 '22 07:11

Warren Weckesser