scipy stats.moment () function | python


Its formula is —

Parameters:
array: Input array or object having the elements to calculate the moment.
axis: Axis along which the moment is to be computed. By default axis = 0.
moment: Order of central moment that is returned.

Returns: n-th central moment of the array elements based on the set parameters.

Code # 1:

# Moment

from scipy import stats

import numpy as np 

 

arr1 = np.array ([[ 1 , 31 , 27 , 13 , 21 , 9 ],

[ 8 , 12 , 8 , 4 , 7 , 10 ]]) 

 

 

print ( "Oth moment:" , stats.moment (arr1, moment = 0 )) 

Output:

 Oth moment: [1 ... 1. 1. 1. 1. 1.] 

Code # 2: with multidimensional data

Output:

 Oth moment: [1. 1. 1.] 6th moment: [5.20609375e + 02 9.13256836e + 00 4.26392850e + 06] 9th moment: 55265909588.26437 12th moment: [1.53284936e + 14 1.63654317e + 02 8.83474172e + 03 5.17842143e + 04] 10th moment: [5.53094361e + 11 6.10464868e + 01 1.64971407e + 03 7.65588508e + 03] 

# Moment

from scipy import stats

import numpy as np 

 

arr1 = [[ 1 , 3 , 27 ], 

[ 3 , 4 , 6  ], 

[ 7 , 6 , 3 ], 

[ 3 , 6 , 8 ]] 

 

print ( "Oth moment:" , stats.moment (arr1, moment = 0 ))

 

print ( "6th moment:" , stats.momen t (arr1, moment = 6 ))

 

print ( "9th moment:" , stats.moment (arr1, moment = 9 , axis = None ))

 

print ( "12th moment:" , stats. moment (arr1, moment = 12 , axis = 1 ))

 

print ( "10th moment:" , stats.moment (arr1, moment = 10 , axis = 1 ))