I\'d like to write a function that normalizes the rows of a large sparse matrix (such that they sum to one).
from pylab import * import scipy.sparse as sp d
This has been implemented in scikit-learn sklearn.preprocessing.normalize.
from sklearn.preprocessing import normalize w_normalized = normalize(w, norm='l1', axis=1)
axis=1 should normalize by rows, axis=0 to normalize by column. Use the optional argument copy=False to modify the matrix in place.
axis=1
axis=0
copy=False