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