Change language

Python | Find average value of list Numpy Array

| |

Method # 1: Using np.mean ()

# Python code to find the average of each array in the list

 
# Import Module

import numpy as np

 
# Initialization list

Input = [np.array ([ 1 , 2 , 3 ]),

np.array ([ 4 , 5 , 6 ]),

np.array ([ 7 , 8 , 9 ])]

  
# Initialize the output list

Output = []

 
# using np.mean ()

for i in range ( len ( Input )):

  Output.append (np.mean ( Input [i]) )

 
# Printout

print (Output)

Exit:

 [2.0, 5.0, 8.0] 

Method # 2: Using np.average ()

# Python code to find the average
# each numpy array in the list

 
# Importer

import numpy as np

 
# Initialization list

Input = [np.array ([ 11 , 12 , 13 ]),

  np.array ([ 14 , 15 , 16 ]),

np.array ([ 17 , 18 , 19 ] )]

 
# Initialize the output list

Output =  []

 
# using np.mean ()

for i in range ( len ( Input )):

Output.append (np.average ( Input [i]))

 
# Printout

print (Output)

Output:

 [12.0, 15.0, 18.0] 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method