scipy.stats.

# trim1#

scipy.stats.trim1(a, proportiontocut, tail='right', axis=0)[source]#

Slice off a proportion from ONE end of the passed array distribution.

If proportiontocut = 0.1, slices off ‘leftmost’ or ‘rightmost’ 10% of scores. The lowest or highest values are trimmed (depending on the tail). Slice off less if proportion results in a non-integer slice index (i.e. conservatively slices off proportiontocut ).

Parameters:
aarray_like

Input array.

proportiontocutfloat

Fraction to cut off of ‘left’ or ‘right’ of distribution.

tail{‘left’, ‘right’}, optional

Defaults to ‘right’.

axisint or None, optional

Axis along which to trim data. Default is 0. If None, compute over the whole array a.

Returns:
trim1ndarray

Trimmed version of array a. The order of the trimmed content is undefined.

Examples

Create an array of 10 values and trim 20% of its lowest values:

```>>> 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])
```

Note that the elements of the input array are trimmed by value, but the output array is not necessarily sorted.

The proportion to trim is rounded down to the nearest integer. For instance, trimming 25% of the values from an array of 10 values will return an array of 8 values:

```>>> b = np.arange(10)
>>> stats.trim1(b, 1/4).shape
(8,)
```

Multidimensional arrays can be trimmed along any axis or across the entire array:

```>>> 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,)
```