Reputation:
I used the following code to sum all the rows in a 2D matrix but I want to sum all the columns instead:
row_sum = sum(map(sum,[arr]))
Upvotes: 0
Views: 105
Reputation: 1489
You can try the code below:
import numpy as np
arr: <2D matrix>
col_sum = np.sum(arr, axis=1, keepdims=True)
Upvotes: 1