Python Practice › NumPy Programs › Program 37
Sum of each column
Write a NumPy program to calculate the sum of each column.
Input
[[5, 3], [7, 4]]
Output
[12 7]
Approach
sum(axis=0).
Solution
import numpy as npprint(np.array([[5, 3], [7, 4]]).sum(axis=0))Output
[12 7]
Learn the concept
New to this topic? Read the lesson, then come back.