For sparse matrices, we usually pass in column indices (indices) and an indptr vector that indexes the indices vector so that indices[indptr[i]:indptr[i+1]] are the elements of row i in the sparse matrix.
Is there a fast, vectorized, preferably numpy solution to convert a vector of consecutive
row indices into an indptr in Python?
For example, if this is my rows indices vector: [0,1,1,2,2,2,3,5]...
The indptr vector would be [0,1,3,6,7,7,8] where the 7 repeats because the row vector is missing row 4.
I can do it using a simple loop:
for i in range(len(rows)):
indptr[rows[i]+1] += 1
indptr=np.cumsum(indptr)
But I was wondering if there's a faster, vectorized way to do it?