What form do you want these indices in? For example
x=sparse.csr_matrix([[1,2,0,3,0,0],[0,0,0,1,0,0]])
In [15]: for r in x:
....: print r.nonzero()
(array([0]), array([0]))
(array([0, 0]), array([0, 2]))
(array([0, 0, 0]), array([0, 1, 2]))
In [30]: [r.nonzero()[1] for r in x] # or as list
Out[30]: [array([0]), array([0, 2]), array([0, 1, 2])]
In [16]: x.nonzero()
Out[16]: (array([0, 1, 1, 2, 2, 2]), array([0, 0, 2, 0, 1, 2]))
nonzero
on the whole matrix has the same numbers, but they aren't split into sublists. But the tolil
format has the same information as a list of lists.
In [18]: xl=x.tolil()
In [19]: xl.rows
Out[19]: array([[0], [0, 2], [0, 1, 2]], dtype=object)
In [23]: xc=x.tocoo()
In [24]: xc.row
Out[24]: array([0, 1, 2, 2, 1, 2])
In [25]: xc.col
Out[25]: array([0, 0, 0, 1, 2, 2])
In a coo
format, the same indices are there, but the order is different. But convert it first to csr
and the order is
In [29]: x.tocsr().tocoo().col
Out[29]: array([0, 0, 2, 0, 1, 2])