Середнє арифметичне

Follow this program to use the mathematical formula.

listnumbers=[1,2,4];
print("The mean is =",sum(listnumbers) / len(listnumbers));

Output:

The mean is = 2.3333333333333335

The NumPy standard library contains the mean() functionarrow-up-right used to determine the Arithmetic Mean in Python. For this, import the NumPy library first. See the example below.

import numpy
listnumbers = [1, 2, 4]
print ("The mean is =",numpy.mean(listnumbers))

Output:

The mean is = 2.3333333333333335

The statistics library contains the mean() function used to determine the Arithmetic Mean. For this, import the statistics library first. Follow the example below.

import statistics
listnumbers = [1, 2, 4]
print("The mean is =",statistics.mean(listnumbers))

Output:

The scipy library contains the mean() function used to determine the mean. For this, import the scipy library first. Here’s an example.

Output:

Использование операции уменьшения

Вы также можете вычислить среднее значение с помощью функции сокращения. Это будет переведено в простой код ниже:

Last updated