Setting Elements In .data Attribute To Zero Unpleasant Behaivor In Scipy.sparse
I getting unpleasant behavior when I set values in .data of csr_matrix to zero. Here is an example: from scipy import sparse a = sparse.csr_matrix([[0,0,2,0], [1,1,0,0],[0,3,0,0]])
Solution 1:
Sparse matrices in scipy (at least CSC and CSR) have an .eliminate_zeros()
method to handle this situations. Run
a.eliminate_zeros()
every time you mess with a.data
, and it should take care of it.
Post a Comment for "Setting Elements In .data Attribute To Zero Unpleasant Behaivor In Scipy.sparse"