Change language

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] 

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically

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