Calculate average values of two given NumPy arrays
Last Updated :
20 Aug, 2020
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 numpy as np
arr1 = np.array([ 3 , 4 ])
arr2 = np.array([ 1 , 0 ])
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 numpy as np
arr1 = np.array([[ 3 , 4 ], [ 8 , 2 ]])
arr2 = np.array([[ 1 , 0 ], [ 6 , 6 ]])
avg = (arr1 + arr2) / 2
print ( "Average of NumPy arrays:\n" ,
avg)
|
Output:
Average of NumPy arrays:
[[2. 2.]
[7. 4.]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...