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

### [Use the Mathematical Formula to Calculate the Arithmetic Mean in Python](https://www.delftstack.com/howto/python/calculate-python-mean/#use-the-mathematical-formula-to-calculate-the-arithmetic-mean-in-python) <a href="#use-the-mathematical-formula-to-calculate-the-arithmetic-mean-in-python" id="use-the-mathematical-formula-to-calculate-the-arithmetic-mean-in-python"></a>

Follow this program to use the mathematical formula.

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

Output:

```
The mean is = 2.3333333333333335
```

### [Use the `numpy.mean()` Function to Calculate the Arithmetic Mean in Python](https://www.delftstack.com/howto/python/calculate-python-mean/#use-the-numpymean-function-to-calculate-the-arithmetic-mean-in-python) <a href="#use-the-numpymean-function-to-calculate-the-arithmetic-mean-in-python" id="use-the-numpymean-function-to-calculate-the-arithmetic-mean-in-python"></a>

The `NumPy` standard library contains [the `mean()` function](https://www.delftstack.com/api/numpy/python-numpy-mean/) used to determine the Arithmetic Mean in Python. For this, import the `NumPy` library first. See the example below.

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

Output:

```
The mean is = 2.3333333333333335
```

### [Use the `statistics.mean()` Function to Calculate the Arithmetic Mean in Python](https://www.delftstack.com/howto/python/calculate-python-mean/#use-the-statisticsmean-function-to-calculate-the-arithmetic-mean-in-python) <a href="#use-the-statisticsmean-function-to-calculate-the-arithmetic-mean-in-python" id="use-the-statisticsmean-function-to-calculate-the-arithmetic-mean-in-python"></a>

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

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

Output:

```
The mean is = 2.3333333333333335
```

### [Use the `scipy.mean()` Function to Calculate the Arithmetic Mean in Python](https://www.delftstack.com/howto/python/calculate-python-mean/#use-the-scipymean-function-to-calculate-the-arithmetic-mean-in-python) <a href="#use-the-scipymean-function-to-calculate-the-arithmetic-mean-in-python" id="use-the-scipymean-function-to-calculate-the-arithmetic-mean-in-python"></a>

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

```python
import scipy;
listnumbers=[1,2,4];
print("The mean is =",scipy.mean(listnumbers));
```

Output:

```
The mean is = 2.3333333333333335
```

### Использование операции уменьшения <a href="#reduce_operation" id="reduce_operation"></a>

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

```python
from functools import reduce
 
if __name__ == '__main__':
 
    ints = [1, 2, 3, 4, 5]
 
    avg = reduce(lambda x, y: x + y, ints) / len(ints)
    print(avg)        # 3.0
 
```
