I have a sparse matrix. I need to sort this matrix row-by-row and create another [sparse] matrix. Code may explain it better:
# for `rand` function, you need newer version of scipy. from scipy.sparse import * m = rand(6,6, density=0.6) d = m.getrow(0) print d Output1
(0, 5) 0.874881629788 (0, 4) 0.352559852239 (0, 2) 0.504791645463 (0, 1) 0.885898140175 I have this m matrix. I want to create a new matrix with sorted version of m. The new matrix contains 0'th row like this.
new_d = new_m.getrow(0) print new_d Output2
(0, 1) 0.885898140175 (0, 5) 0.874881629788 (0, 2) 0.504791645463 (0, 4) 0.352559852239 So I can obtain which column is bigger etc:
print new_d.indices Output3
array([1, 5, 2, 4]) Of course every row should be sorted like above independently.
I have one solution for this problem but it is not elegant.