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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -