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
Use masked arrays:
>>> a = numpy.array([2, 0, 1.5, -3]) >>> b = numpy.ma.log(a) >>> b masked_array(data = [0.69314718056 -- 0.405465108108 --], mask = [False True False True], fill_value = 1e+20) >>> b.sum() 1.0986122886681096