Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get more detailed error information numpy for "RuntimeWarning: invalid value encountered in multiply" error

Is there a way to get more detailed from numpy for the error message

"RuntimeWarning: invalid value encountered in multiply"

It comes from a certain line in the code where I"m doing a number of array operations. Can I get numpy to report:

(1) More information on the invalid value (inf? nan?)

(2) The array entry that is causing the problem?

Of course I can inspect the array myself but it would be nice if numpy could just tell me what and where the problem is.

like image 399
Anthony Bak Avatar asked Feb 20 '13 17:02

Anthony Bak


1 Answers

You can probably at least get more information on the type of error by numpy.seterrcall (in conjunction with numpy.seterr as demonstrated in the link). As far as figuring out which array is giving the problems, that probably isn't possible as numpy necessarily creates temporary arrays:

a = b + (c*d)
#       ^This creates a temporary array before adding it to `a`

Of course, you could use seterr to raise exceptions instead of warnings if you want to know what line number is the offending one in your code.

like image 74
mgilson Avatar answered Oct 27 '22 15:10

mgilson