Skip to content
Related Articles
Open in App
Not now

Related Articles

Calculate average values of two given NumPy arrays

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 20 Aug, 2020
Improve Article
Save Article

Finding average of NumPy arrays is quite similar to finding average of given numbers. We just have to get the sum of corresponding array elements and then divide that sum with the total number of arrays.

Let’s see an example:

Example 1: Calculate average values of two given NumPy 1d-arrays

Python3




# import library
import numpy as np
  
#  create a numpy 1d-arrays
arr1 = np.array([3, 4])
arr2 = np.array([1, 0])
  
# find average of NumPy arrays
avg = (arr1 + arr2) / 2
  
print("Average of NumPy arrays:\n",
      avg)

Output:

Average of NumPy arrays:
 [2. 2.]

Example 2: Calculate average values of two given NumPy 2d-arrays

Python3




# import library
import numpy as np
  
#  create a numpy 2d-arrays
arr1 = np.array([[3, 4], [8, 2]])
arr2 = np.array([[1, 0], [6, 6]])
  
# find average of NumPy arrays
avg = (arr1 + arr2) / 2
  
print("Average of NumPy arrays:\n",
      avg)

Output:

Average of NumPy arrays:
 [[2. 2.]
 [7. 4.]]
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!