. Advertisement .
..3..
. Advertisement .
..4..
Hi guys! I encounter the ”runtimewarning: divide by zero encountered in log” error when I am using numpy.log10 to calculate the log of an array of probability values.
The array has some zeros, and I’m attempting to get around this using:
result = numpy.where(prob > 0.0000000001, numpy.log10(prob), -10)
And then I get the message:
Error: runtimewarning: divide by zero encountered in log
I don’t know why this error occurs and how to fix? Can you help me?
Solution: Before taking the logarithm, you can use
10**-10
or some other dummy value to fill theprob
‘s zeros. But be careful not to compute prob > 0.0000000001 using dummy values.