0

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?

0

1 Answer 1

0

Use tile to repeat it along the dimension on which sum operated.

M / np.tile(np.sum(M, 1), (1, M.shape[1]))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.