I have the following code:
def lfun(A):
return np.where(A != 0, np.log(A), A)
B = np.array([[1,20,0],[10,0,20]])
C = lfun(B)
print(C)
The point is to take an array, calculate the log of the nonzero entries of the array, and leave the zero entries as simply zero (instead -inf or nan). When I run the code, it does what I want, however it also gives me a strange error:
"RuntimeWarning: divide by zero encountered in log"
Why is it dividing by zero?