Last active
December 18, 2024 22:33
-
-
Save vtraag/8b82e10e57d93eacc524 to your computer and use it in GitHub Desktop.
Permute sparse matrix in Python using scipy COO format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def permute_sparse_matrix(M, order): | |
permuted_row = order[M.row]; | |
permuted_col = order[M.col]; | |
new_M = sparse.coo_matrix((M.data, (permuted_row, permuted_col)), shape=M.shape); | |
return new_M; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code looks fine to me.
order
is the permutation array that defines the old-to-new reindexing.