Python Practice › NumPy Programs › Program 35

Sum of all elements

EasyNumPy Programs · 35 of 100

Write a NumPy program to calculate the sum of all elements.

Advertisement
Input
[[5, 3], [7, 4]]
Output
19

Approach

  1. .sum().

Solution

Python
import numpy as npprint(np.array([[5, 3], [7, 4]]).sum())
Output
19
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs