问题
I have 2 scipy.sparse.csr_matrix
like this:
A = [ 1 0 1 0 0 1
1 0 0 1 0 0
0 1 0 0 0 0 ]
B = [ 1 0 1 0 1 1
1 1 0 1 0 0
1 1 1 0 0 0 ]
I am willing to get the "new ones" that appeared in B but weren't in A.
C = [ 0 0 0 0 1 0
0 1 0 0 0 0
1 0 1 0 0 0 ]
回答1:
IIUC it should be pretty straightforward:
In [98]: C = B - A
In [99]: C
Out[99]:
<3x6 sparse matrix of type '<class 'numpy.int32'>'
with 4 stored elements in Compressed Sparse Row format>
In [100]: C.A
Out[100]:
array([[0, 0, 0, 0, 1, 0],
[0, 1, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0]], dtype=int32)
来源:https://stackoverflow.com/questions/46798631/difference-between-2-scipy-sparse-csr-matrices