I have an NxM array in numpy that I would like to take the log of, and ignore entries that were negative prior to taking the log. When I take the log of negative entries, it
Alternative to using masked arrays....
import numpy as np
myarray = np.array([2, 0, 1.5, -3])
mylogarray = np.log(myarray) # The log of negative numbers is nan, 0 is -inf
summed = mylogarray[np.isfinite(mylogarray)].sum() # isfinite will exclude inf and nan
print(f'Sum of logged array is: {summed}')
>>> Sum of logged array is: 1.0986122886681096