python - invalid value encountered in log python - invalid value encountered in log python python

python - invalid value encountered in log


You probably still have negative values inside the log, which gives nan with real numbers.

a and y should represent probability between 0 to 1, So you need to check why do you have smaller/larger values there. Adding 1e-7 shows there is something fishy, because np.log(0) gives -inf, which I think is the value you want.


You can use math.log() replacing numpy.log(), which could raise error

>>> import numpy>>> numpy.log(0)-inf>>> numpy.__version__'1.3.0'>>> import math>>> math.log(0)Traceback (most recent call last):  File "<stdin>", line 1, in <module>ValueError: math domain error