scipy.stats.
trim1#
- scipy.stats.trim1(a, proportiontocut, tail='right', axis=0)[source]#
从传递的数组分布的**一端**切掉一个比例。
如果 proportiontocut = 0.1,则切掉“最左边”或“最右边”10%的分数。 最低或最高的值被修剪(取决于尾部)。如果比例导致非整数切片索引,则切掉较少(即保守地切掉 proportiontocut)。
- 参数:
- aarray_like
输入数组。
- proportiontocutfloat
从分布的“左侧”或“右侧”切断的比例。
- tail{‘left’, ‘right’}, optional
默认为“right”。
- axisint or None, optional
要沿其修剪数据的轴。 默认为 0。如果为 None,则在整个数组 a 上计算。
- 返回:
- trim1ndarray
数组 a 的修剪版本。 修剪内容的顺序未定义。
例子
创建一个包含 10 个值的数组,并修剪掉其最低值的 20%
>>> import numpy as np >>> from scipy import stats >>> a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> stats.trim1(a, 0.2, 'left') array([2, 4, 3, 5, 6, 7, 8, 9])
请注意,输入数组的元素按值修剪,但输出数组不一定排序。
要修剪的比例向下舍入到最接近的整数。 例如,从包含 10 个值的数组中修剪掉 25% 的值将返回一个包含 8 个值的数组
>>> b = np.arange(10) >>> stats.trim1(b, 1/4).shape (8,)
可以沿任何轴或跨整个数组修剪多维数组
>>> c = [2, 4, 6, 8, 0, 1, 3, 5, 7, 9] >>> d = np.array([a, b, c]) >>> stats.trim1(d, 0.8, axis=0).shape (1, 10) >>> stats.trim1(d, 0.8, axis=1).shape (3, 2) >>> stats.trim1(d, 0.8, axis=None).shape (6,)