Skip to content

Instantly share code, notes, and snippets.

@venuktan
venuktan / gist:8910385
Last active December 15, 2020 13:17 — forked from dwf/gist:828099
Pull out a submatrix from a COO SciPy sparse matrix.
import scipy as S
def coo_submatrix_pull(matr, rows, cols):
"""
Pulls out an arbitrary i.e. non-contiguous submatrix out of
a sparse.coo_matrix.
"""
if type(matr) != S.sparse.coo_matrix:
raise TypeError('Matrix must be sparse COOrdinate format')