[Numpy-discussion] Non-Zero Sub-Matrix

Radek Machulka radek.machulka@gmail....
Fri Sep 10 04:46:47 CDT 2010


Hi Folks,

I have array (numpy.ndarray object) with non-zero elements cumulated
'somewhere' (like a array([[0,0,0,0],[0,1,1,0],[0,0,1,0],[0,0,0,0]]))
and I need sub-array with just non-zero elements
(array([[1,1],[0,1]])).
I can do this with iterating throught an array, but I also found some
magic tricks with boolen operators in indexing and nonzero function,
but it is still not clear to me, how to use it.

I am sure that this will be pretty easy for those who are familiar
with this kind of array indexing and I hope I will be one of them soon
:-).

Thanks a lot
Radek


More information about the NumPy-Discussion mailing list