bundles / scipy latest / scipy / stats / _stats_py / trim1
function
scipy.stats._stats_py:trim1
source: /scipy/stats/_stats_py.py :3549
Signature
def trim1 ( a , proportiontocut , tail = right , axis = 0 ) Summary
Slice off a proportion from ONE end of the passed array distribution.
Extended Summary
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
a: array_likeInput array.
proportiontocut: floatFraction to cut off of 'left' or 'right' of distribution.
tail: {'left', 'right'}, optionalDefaults to 'right'.
axis: int or None, optionalAxis along which to trim data. Default is 0. If None, compute over the whole array
a.
Returns
trim1: ndarrayTrimmed version of array
a. The order of the trimmed content is undefined.
Notes
Array API Standard Support
trim1 has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
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')✓
b = np.arange(10) stats.trim1(b, 1/4).shape✓
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 stats.trim1(d, 0.8, axis=1).shape stats.trim1(d, 0.8, axis=None).shape✓
Aliases
-
scipy.stats.trim1