📜  sciPy stats.tmean() | Python(1)

📅  最后修改于: 2023-12-03 15:05:05.665000             🧑  作者: Mango

stats.tmean() in SciPy Python Library

The stats.tmean() function is used to compute the trimmed mean of a dataset. It is part of the scipy.stats module in the SciPy library.

Syntax

The syntax for using stats.tmean() function is as follows:

scipy.stats.tmean(a, limits=None, inclusive=(True, True))
Parameters
  • a: It is the input data array.
  • limits: It is a tuple of the lower and upper trimming values. Data outside these limits are ignored.
  • inclusive: It specifies whether the limits are inclusive or exclusive. By default, it is set to (True, True).
Return Value

The stats.tmean() function returns the trimmed mean of the dataset.

Example Usage
import numpy as np
from scipy import stats

# Creating a sample dataset
data = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

# Computing the trimmed mean with limits (2, 9) inclusive
t_mean = stats.tmean(data, (2, 9), (True, True))

# Printing the trimmed mean value
print(t_mean)

Output:

5.5

In the above example, we first created a sample dataset containing 10 elements. Then we used the stats.tmean() function to compute the trimmed mean of the dataset with limits (2, 9) inclusive. The resulting trimmed mean value of the dataset is 5.5, which is printed to the console.

Conclusion

In summary, the stats.tmean() function in the SciPy Python library is a useful tool for computing the trimmed mean of a dataset. It can be helpful in situations where outliers or extreme values can skew the mean of the dataset, and a trimmed mean can provide a more representative estimate of the central tendency.