python - Finding the indices of the rows where there are non-zero entries in a sparse csc_matrix -
i have numpy array, x:
type(x) >>> <class 'scipy.sparse.csc.csc_matrix'> i interested in finding indices of rows there non-zero entries, in 0th column. tried:
getcol = x.getcol(0) print getcol which gives me:
(0, 0) 1 (2, 0) 1 (5, 0) 10 this great, want vector has 0, 2, 5 in it.
how indices i'm looking for?
thanks help.
with csc matrix can following:
>>> import scipy.sparse sps >>> = 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 after.
Comments
Post a Comment