I'm using function: numpy.log(1+numpy.exp(z))
for small values of z (1-705) it gives identity result(1-705 {as expected}), but for larger value of z from 710+ it gives infinity, and throw error "runtimeWarning: overflow encountered in exp"
For large z you could use
z + log(exp(-z) + 1)
which is mathematically but not numerically the same thing.
In code:
(z + np.log(np.exp(-z) + 1)) if z > 0 else np.log(1 + np.exp(z))
If you need a vectorised version:
np.maximum(z, 0) + np.log(np.exp(-np.absolute(z)) + 1)
As @Praveen points out there is a function np.log1p which calculates log(1+x) but is more accurate if |x| is small. I recommend using it in the above.
What is happening is that you are overflowing the register such that it is overwriting itself. You have exceeded the maximum value that can be stored in the register. You will need to use a different datatype that will most likely not be compatible with exp(.). You might need a custom function that works with 64-bit Integers.
log(1 + exp(705))is approximately 705. The+1makes nearly no difference becausee^705is just so huge. You can just catch the error and set the value to be equal toz.