I'm trying to "translate" some Matlab code into Python and there is one line in Matlab that sets multiple rows in a sparse matrix to 0s:
Ks(idx,:)=0; %no affinity for W inside fs
where Ks
is the sparse matrix (which is symmetrical and with pretty big size), and idx
is an 1D array denoting the row indices to do the changes and it's also quite big in size. And in the next line it also changes those columns to 0s, so Ks
is still symmetric:
Ks(:,idx)=0;
Doing the similar thing in Python (Ks[idx,:]=0
) seems to only work for small matrices, when it gets big I got MemoryError
. Currently my Ks
is a csr matrix, converting it to lil
and do that is super slow.
I'm not quite familiar with sparse matrices, I know that in Python there are more than 1 type (e.g. csr, csc, lil etc.), but in the Matlab code there aren't such distinctions, I only found a function call of sparse()
. So what's my best bet in this situation?
Thanks in advance.