Question: How can I split 1 sparse matrix into 2, based on the values ββin the list?
That is, I have a sparse matrix X :
>>print type(X) <class 'scipy.sparse.csr.csr_matrix'>
which I imagine in my head as a list of lists to look like this:
>>print X.todense() [[1,3,4] [3,2,2] [4,8,1]]
And I have a list y that looks like this:
y = [-1, 3, -4]
How can I separate X from two sparse matrices, depending on whether the corresponding value in y positive or negative? For example, how can I get:
>>print X_pos.todense() [[3,2,2]] >>print X_neg.todense() [[1,3,4] [4,8,1]]
The result ( X_pos and X_neg ) should also be sparse matrices, obviously, since it just splits the sparse matrix to begin with.
Thanks!
source share