Thursday 15 January 2015

python - Apply logarithm only on positive entries of array -


SciPy wisely provides the scipy.log function, which will take an array and then log all the elements in that array. Is there any way of logging only positive (i.e. positive non-zero) elements of an array?

about ou () ?

  import np as np a = np.array ([1., -1, 0.5, -0.5, 0., 2.]] La = np.where (a & gt; 0, np.log (a), a) Print (La) # returns [0. -1 -0.69314718 -0.5 0. 0.69314718]  

No comments:

Post a Comment