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()

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to find mean of every numpy array in list
  
# Importing module
import numpy as np
  
# List Initialization
Input = [np.array([1, 2, 3]),
         np.array([4, 5, 6]),
         np.array([7, 8, 9])]
  
# Output list initialization
Output = []
  
# using np.mean()
for i in range(len(Input)):
   Output.append(np.mean(Input[i]))
  
# Printing output
print(Output)

chevron_right


Output:



[2.0, 5.0, 8.0]

 
Method #2: Using np.average()

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to find mean of 
# every numpy array in list
  
# Importing module
import numpy as np
  
# List Initialization
Input = [np.array([11, 12, 13]),
         np.array([14, 15, 16]),
         np.array([17, 18, 19])]
  
# Output list initialization
Output = []
  
# using np.mean()
for i in range(len(Input)):
   Output.append(np.average(Input[i]))
  
# Printing output
print(Output)

chevron_right


Output:

[12.0, 15.0, 18.0]


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.