Let’s explore how to sum an array using the NumPy Python library.
Numpy sum array
There is Numpy built-in function which will help you to sum up array elements.
import numpy as np my_array = np.array([1, 56, 55, 15, 0]) array_sum = np.sum(my_array) print(f"Sum equals: {array_sum}")
The NumPy sum function totals all elements in the array and returns the result.
How to sum up array in Numpy?
To calculate the sum of an array in NumPy, simply follow these steps:
- Import the
numpy
library. - Create a Numpy array.
- Apply the
sum()
function to the array. - Output the sum.