Skip to content
Related Articles

Related Articles

Python | Find Mean of a List of Numpy Array
  • Last Updated : 14 Mar, 2019

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




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


Output:

[2.0, 5.0, 8.0]

 
Method #2: Using np.average()




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


Output:

[12.0, 15.0, 18.0]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :