OKPEDIA PYTHON STATISTICA EN

How to calculate the arithmetic mean in python

To calculate the arithmetic mean in Python, you can use the mean () function of the numpy library.

mean(x)

The x parameter of the function is a list of numeric values or an array containing the values.

The mean() function calculates and returns the arithmetic mean of the distribution.

$$ μ = \frac{ \sum_{i=1}^{n} x_i } {n} $$

Examples

Example 1

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

3.0

Example 2

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

2.0

Example 3

from numpy import mean, array
v=array([1,2,3,4])
mean(v)

2.5

https://how.okpedia.org/en/python/how-to-calculate-the-arithmetic-mean-in-python


Report us an error or send a suggestion to improve this page


Statistics in python


FacebookTwitterLinkedinLinkedin