- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Mean of a List of Numpy Array in Python
Numpy is a very powerful python library for numerical data processing. It mostly takes in the data in form of arrays and applies various functions including statistical functions to get the result out of the array. In this article we will see how to get the mean value of a given array.
with mean
The mean function can take in an array and give the mathematical mean value of all the elements in it. So we design a for loop to keep track of the length of the input and go through each array calculating its mean.
Example
import numpy as np # GIven Array Arrays_In = [np.array([11, 5, 41]), np.array([12, 13, 26]), np.array([56, 20, 51])] # Resultihg Array Arrays_res = [] # With np.mean() for x in range(len(Arrays_In)): Arrays_res.append(np.mean(Arrays_In[x])) # Result print("The means of the arrays: \n",Arrays_res)
Output
Running the above code gives us the following result −
The means of the arrays: [19.0, 17.0, 42.333333333333336]
with Average
It is a very similar approach as above except that we use the average function instead of mean function. It gives the exact same result.
Example
import numpy as np # GIven Array Arrays_In = [np.array([11, 5, 41]), np.array([12, 13, 26]), np.array([56, 20, 51])] # Resultihg Array Arrays_res = [] # With np.average() for x in range(len(Arrays_In)): Arrays_res.append(np.average(Arrays_In[x])) # Result print("The means of the arrays: \n",Arrays_res)
Output
Running the above code gives us the following result −
The means of the arrays: [19.0, 17.0, 42.333333333333336]
- Related Articles
- Create a record array from a (flat) list of array in Numpy
- Program to find mean of array after removing some elements in Python
- Numpy Array advantage over a Nested List
- Find mean of subarray means in a given array in C++
- Create a record array from a (flat) list of array and fetch arrays using names in Numpy
- How to find the mean of list elements in R?
- Python Pandas - Return numpy array of python datetime.date objects
- Python Pandas - Return numpy array of python datetime.time objects
- Change data type of given numpy array in Python
- Return a list of slices corresponding to the masked clumps of a 1-D array in Numpy
- Return a list of slices corresponding to the unmasked clumps of a 1-D array in Numpy
- Find average of a list in python?
- Find size of a list in Python
- Create a record array from a (flat) list of array and set a valid datatype for all in Numpy
- What does the slash(/) in the parameter list of a function mean in Python?

Advertisements