0

indptr points to row starts in indices and data. I have transformed my matrix into csr matrix by np.savez(). However, I noticed that the first elements of indptr is as follows:

1
1
23
195
213
256
284
317

which says that the first row and the second row start with the same data. What causes this error, or is this an error?

MaxU - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419

1 Answers1

1

It means that the 2nd row is all zeros

In [187]: from scipy import sparse
In [191]: M=sparse.csr_matrix([[0,0,1],[0,0,0],[0,1,0],[1,1,0]])
In [192]: M.A
Out[192]: 
array([[0, 0, 1],
       [0, 0, 0],
       [0, 1, 0],
       [1, 1, 0]], dtype=int32)
In [193]: M.indptr
Out[193]: array([0, 1, 1, 2, 4], dtype=int32)

(though the missing 0 at the start of indptr is a bit of a concern.)

What does the .A (toarray()) show?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • hpaulj, can you look at the problem here: http://stackoverflow.com/questions/43460945/csr-inconsistency-between-indices-and-indptr –  Apr 17 '17 at 22:59