I have an expression that overflows for certain values of parameters. In this case, I have derived what the asymptotic result should be using pen and paper, and when I have such a case I just replace with my analytical expression.
At the moment my code does something like this:
values = ExpressionThatOverFlows()
# Check the ones that overflow
indOverFlow = isnan(values)
# Set them to the values I derived by pen and paper
values[indOverFlow] = derivedValues
My problem is that the I/O explodes with "warnings". I know that it is good that it warns me, but I have explicitly taken care of it so I want to silence them. Note that I do not want to silence all types of "overflow" warnings, only the ones here. I thought that something like this would work but it did not:
try:
values = ExpressionThatOverFlows()
except Warning:
pass
# and the rest of the code as it is
I have checked around but I just seem to find how to silence these warnings for an entire session or forever, but this is as I pointed out not what I want.
Thanks for your help, much appreciated.
EDIT: Here comes a much smaller code that generates the problem I have:
from scipy import log1p, exp
from numpy import array, isnan
a = array([0.2222, 500.3, 0.3, 700.8, 0.111])
values = log1p(-exp(-exp(10**a - 9**a)))
print values # Note the nan's
indOverflow = isnan(values)
values[indOverflow] = 0
Note how I fix the problem "manually" at the end, but what happens in the I/O is:
Warning: overflow encountered in power
Warning: overflow encountered in power
Warning: invalid value encountered in subtract
I do this kind of computations in a loop, so I want to silence these messages (as they are already fixed and furthermore they take a lot of time to print)