larray.LArray.nonzero

LArray.nonzero(self)[source]

Returns the indices of the elements that are non-zero.

Specifically, it returns a tuple of arrays (one for each dimension) containing the indices of the non-zero elements in that dimension.

Returns
tuple of arraystuple

Indices of elements that are non-zero.

Examples

>>> arr = ndtest((2, 3))
>>> arr
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
>>> cond = arr > 1
>>> cond
a\b     b0     b1    b2
 a0  False  False  True
 a1   True   True  True
>>> a, b = cond.nonzero()
>>> a
a.i[a_b  a0_b2  a1_b0  a1_b1  a1_b2
         0      1      1      1]
>>> b
b.i[a_b  a0_b2  a1_b0  a1_b1  a1_b2
         2      0      1      2]
>>> # equivalent to arr[cond]
>>> arr[cond.nonzero()]
a_b  a0_b2  a1_b0  a1_b1  a1_b2
         2      3      4      5