I am running loops with linear regression and got calculations going where I often end up with infinities. When I check the variable output, I note that things crash when I start getting "NaNs". I've tried a lot of different ways of dealing with infinities but my program still ends up crashing. I've done things like replace NaNs with very large or very small values, but now I'm thinking this is all no use. I shouldn't be treating all NaNs equally - apparently some NaNs come about while playing with positive infinities, and some with negative infinities.
I really need to know at WHICH point exactly does my code suddenly produce a NaN, and whether it was a negative infinity that produced it, or a positive one. How can I do this, before the program crashes?
Edit
I know how to check for NaN. I can simply use numpy.isnan
, and I have used it. But I want to know when it happens. Isn't there an exception or something that can be called or throw a warning when it happens?