For example,
M= [[1,2], [7,8]]
then I want
[[1/3, 2/3], [7/15, 8/15]]
I'm trying to do this vectorized. One idea I have is to write s = np.sum(M, axis=1); this gives us the corresponding row sums. Then I could maybe transpose s, and copy it along the columns, then do an elementwise division of M/s, but even this seems too hacky. What's the right way?