Instagram
youtube
Facebook
Twitter

Find the Sum of All Values in a NumPy Array

     A Find the Sum of All Values in a NumPy Array
     
     Short Description of the Program:

     This program calculates the sum of all elements in a NumPy array using the np.sum() function.
     
     Explanation:

  • np.array()
    Creates a 2D array with numeric values.

     
  • np.sum(array_values)
    Computes the total sum of all values in the array.

     
  • print()
    Displays the original array and the final sum.

Program:

import numpy as np

array_values = np.array([[12, 45, 23], [67, 34, 89]])

total_sum = np.sum(array_values)

print("NumPy Array:\n", array_values)

print("\nSum of All Values in the Array:", total_sum)