Pass a condition to handle discrete or continuous values in the where param for np.log
>>> import numpy as np
>>> x = np.array([0, 1, 2])
>>> np.log(x)
__main__:1: RuntimeWarning: divide by zero encountered in log
array([ -inf, 0. , 0.69314718])
>>>
>>>
>>> np.log(x, where=x > 0)
array([0. , 0. , 0.69314718])
>>> np.log(x, where=x > 0.0)
array([0. , 0. , 0.69314718])
Login