How to sum up array in Numpy?

Let’s explore how to sum an array using the NumPy Python library.
numpy sum

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.

See also  How to convert list to Numpy array

How to sum up array in Numpy?

To calculate the sum of an array in NumPy, simply follow these steps:

  1. Import the numpy library.
  2. Create a Numpy array.
  3. Apply the sum() function to the array.
  4. Output the sum.