I've got a sparse matrix with a few elements. Now I would like to row normalize it. However, when I do this, it gets converted to a numpy array, which is not acceptable from a performance standpoint.
To make things more concrete, consider the following example:
x = csr_matrix([[0, 1, 1], [2, 3, 0]]) # sparse
normalization = x.sum(axis=1) # dense, this is OK
x / normalization # this is dense, not OK, can be huge
Is there an elegant way to do this without having to resort to for loops?
EDIT
Yes, this can be done using sklearn.preprocessing.normalize
using 'l1' normalization, however, I have no wish to depend on sklearn.