I can’t find more info about scipy.sparse indexing except SciPy v0.11 Reference Guide, which says that
The lil_matrix class supports basic slicing and fancy indexing with a similar syntax to NumPy arrays.
. I have read numpy document about index, but I didn’t understand it clearly, for example,
Asp = sparse.lil_matrix((3,3))
Asp.setdiag(zeros(3))
Asp[0, 1:3] = 10
print Asp.todense()
1.
why the output is
[[ 0. 10. 10.] [ 0. 0. 0.] [ 0. 0. 0.]]
what does [0,1:3] meaning? if I use
Asp[0, 1:2,3] = 10
there’s a error:
IndexError: invalid index
, I don’t know the reason.
2.what’s the fastest way to get all non-zero values for each row?
For your second question, use the
nonzero()method. I had to dig through the source to find it, since I couldn’t find it in any of the reference documentation.