indices of sparse_csc matrix are reversed after extracting some columns

Viewed 158

I'm trying to extract columns of a scipy sparse column matrix, but the result is not stored as I'd expect. Here's what I mean:

In [77]: a = scipy.sparse.csc_matrix(np.ones([4, 5]))
In [78]: ind = np.array([True, True, False, False, False])
In [79]: b = a[:, ind]

In [80]: b.indices
Out[80]: array([3, 2, 1, 0, 3, 2, 1, 0], dtype=int32)

In [81]: a.indices
Out[81]: array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=int32)

How come b.indices is not [0, 1, 2, 3, 0, 1, 2, 3] ? And since this behaviour is not the one I expect, is a[:, ind] not the correct way to extract columns from a csc matrix?

2 Answers
Related