OKPEDIA PYTHON STATISTICA EN

How to calculate variance in python

To calculate variance in Python you can use the var() function of the numpy module.

var(x)

The x parameter is a list or array containing the elements of a distribution.

The var() function returns the statistical variance of the distribution.

Examples

Example 1

from numpy import var
a=[1,2,3,4,5]
var(a)

2.0

Example 2

from numpy import var
var([1,2,3])

0.6666666666666666

Example 3

from numpy import var
var([1,1,1])

0.0

https://how.okpedia.org/en/python/how-to-calculate-variance-in-python


Report an error or share a suggestion to enhance this page


Statistics in python


FacebookTwitterLinkedinLinkedin