Skip to content

Instantly share code, notes, and snippets.

View jlaw9's full-sized avatar

Jeff Law jlaw9

View GitHub Profile
@jlaw9
jlaw9 / permute_sparse_matrix.py
Last active November 13, 2020 20:42 — forked from vtraag/permute_sparse_matrix.py
Permute sparse matrix in Python using scipy COO format
from scipy import sparse
def permute_sparse_matrix(M, row_order=None, col_order=None):
"""
Reorders the rows and/or columns in a scipy sparse matrix to the specified order.
"""
if row_order is None and col_order is None:
return M
new_M = M