Reduce a sparse matrix in numpy -
It seems that I'm missing something very basic. I have a large square matrix, which is mostly zero. What I want to reduce is the matrix in which all rows and columns can be with zero-zero entries. For example:
1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 The following should be done in the following: <<> 1 1 1 1 1 1 1 1 1 Is there a quick way to do this?
How about something like this:
& gt; & Gt; & Gt; arr Array ([[1., 1., 0., 1.], [1., 1., 0., 1], [0., 0., 0., 0.], [1., 1 ., 0., 1.]])> Gt; & Gt; & Gt; Mask = (arr == 0) arr = arr [~ np.all (mask, axis = 0)] arr = arr [:, ~ np.all (mask, axis = 1)]> gt; & Gt; & Gt; arr Array ([[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]])
Comments
Post a Comment