In this python numpy program, we will calculate the sum of all elements in an array using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Calculate the sum of all elements in an array using np.sum().
- Print the output.
import numpy as np
x = np.array([[5, 3],
[7, 4]])
print("Sum of all the elements : ",np.sum(x))
Output :
Sum of all the elements : 19