Minimum sparse matrix?

There is no method in scipy.sparse that gives a minimum sparse matrix. In particular, I am looking for a minimum of columns.

There are no methods in the documentation, and the minimum size is not suitable. If X is a sparse matrix, X.min() also throws an error: *** AttributeError: 'module' object has no attribute 'min' .

Of course, this should be something that people use. How it's done?

+6
source share
1 answer

With CSR / CSC matrices use

 def min_sparse(X): if len(X.data) == 0: return 0 m = X.data.min() return m if X.getnnz() == X.size else min(m, 0) 

To do this for each row or column, you can map do this via X.getrow(i) for i in X.shape[0] or X.shape[1] .

But you are right, it must be a method.

+7
source

All Articles