What does the following error:
Warning: overflow encountered in exp
in scipy/numpy using Python generally mean? I'm computing a ratio in log form, i.e. log(a) + log(b) and then taking the exponent of the result, using exp, and using a sum with logsumexp, as follows:
c = log(a) + log(b)
c = c - logsumexp(c)
some values in the array b are intentionally set to 0. Their log will be -Inf.
What could be the cause of this warning? thanks.
解决方案
In your case, it means that b is very small somewhere in your array, and you're getting a number (a/b or exp(log(a) - log(b))) that is too large for whatever dtype (float32, float64, etc) the array you're using to store the output is.
Numpy can be configured to
Ignore these sorts of errors,
Print the error, but not raise a warning to stop the execution (the default)
Log the error,
Raise a warning
Raise an error
Call a user-defined function
See numpy.seterr to control how it handles having under/overflows, etc in floating point arrays.