# HOW IS TRIMMED MEAN CALCULATED IN PYTHON

Trimmed mean can be calculated in Python with the help if SciPy.

`scipy.stats.tmean(array, limits=None, inclusive=(True, True))`

calculates the trimmed mean of the array elements along the specified axis of the array.

*array***:**Input array or object having the elements to calculate the trimmed mean.*axis*: Axis along which the trimmed mean is to be computed. By default, axis = 0.- limits: Lower and upper bound of the array to consider, values less than the lower limit or greater than the upper limit will be ignored. If the limits is None [default], then all values are used.

**Returns :** Trimmed mean of the array elements based on the set parameters.

from scipy import stats import numpy as np # array elements ranging from 0 to 19 x = np.arange(20) print("Trimmed Mean :", stats.tmean(x)) print("\nTrimmed Mean by setting limit : ", stats.tmean(x, (2, 10)))

Output:

Trimmed Mean : 9.5 Trimmed Mean by setting limit : 6.0

Subscribe

Login

Please login to comment

0 Discussion