from sklearn.preprocessing import normalize
matrix = numpy.arange(0, 27, 3).reshape(3, 3).astype(numpy.float64)
normed_matrix = normalize(matrix, axis=1, norm='l1')
How to normalize a 2-dimensional numpy array in python less verbose?