Using a CSC matrix, you can do the following:
>>> import scipy.sparse as sps
>>> a = np.array([[1, 0, 0],
... [0, 1, 0],
... [1, 0, 1],
... [0, 0, 1],
... [0, 1, 0],
... [1, 0, 1]])
>>> aa = sps.csc_matrix(a)
>>> aa.indices[aa.indptr[0]:aa.indptr[1]]
array([0, 2, 5])
>>> aa.indices[aa.indptr[1]:aa.indptr[2]]
array([1, 4])
>>> aa.indices[aa.indptr[2]:aa.indptr[3]]
array([2, 3, 5])
So, aa.indices[aa.indptr[col]:aa.indptr[col+1]]should get what you need.
source
share