Which is pretty close to zero?
>>> np.log(0)
-inf
>>> 0.*np.log(0)
nan
>>> np.log(1e-200)
-460.51701859880916
>>> 1e-200*np.log(1e-200)
-4.6051701859880914e-198
One solution is to add a small positive number to all the probabilities in order to limit them far enough from zero.
The second solution is to explicitly process zeros, for example, replace 0. * np.log (0) with zeros in the resulting array or include only those points that have a nonzero probability in the probability array
source
share