Python | Find Mean of a List of Numpy Array
Given a list of Numpy array, the task is to find mean of every numpy array. Let’s see a few methods we can do the task.
Method #1: Using np.mean()
import numpy as np
Input = [np.array([ 1 , 2 , 3 ]),
np.array([ 4 , 5 , 6 ]),
np.array([ 7 , 8 , 9 ])]
Output = []
for i in range ( len ( Input )):
Output.append(np.mean( Input [i]))
print (Output)
|
Method #2: Using np.average()
import numpy as np
Input = [np.array([ 11 , 12 , 13 ]),
np.array([ 14 , 15 , 16 ]),
np.array([ 17 , 18 , 19 ])]
Output = []
for i in range ( len ( Input )):
Output.append(np.average( Input [i]))
print (Output)
|
Output:
[12.0, 15.0, 18.0]
Last Updated :
14 Mar, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...