Python Practice › NumPy Programs › Program 85
Sum of all columns
Write a NumPy program to calculate the sum of each column.
Input
[[6, 5, 7], [10, 9, 1], [7, 8, 2]]
Output
[23 22 10]
Approach
sum(axis=0).
Solution
import numpy as npprint(np.array([[6, 5, 7], [10, 9, 1], [7, 8, 2]]).sum(axis=0))Output
[23 22 10]
Learn the concept
New to this topic? Read the lesson, then come back.