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