from numpy import * m = array([[1,0], [2,3]])
I would like to compute the element-wise log2(m), but only in the places whe
log2(m)
We can use masked arrays for this:
>>> from numpy import * >>> m = array([[1,0], [2,3]]) >>> x = ma.log(m) >>> print x.filled(0) [[ 0. 0. ] [ 0.69314718 1.09861229]]