bundles / scipy 1.17.1 / scipy / stats / _stats_py / sigmaclip
function
scipy.stats._stats_py:sigmaclip
source: /scipy/stats/_stats_py.py :3382
Signature
def sigmaclip ( a , low = 4.0 , high = 4.0 ) Summary
Perform iterative sigma-clipping of array elements.
Extended Summary
Starting from the full sample, all elements outside the critical range are removed, i.e. all elements of the input array c that satisfy either of the following conditions
c < mean(c) - std(c)*low c > mean(c) + std(c)*high
The iteration continues with the updated sample until no elements are outside the (updated) range.
Parameters
a: array_likeData array, will be raveled if not 1-D.
low: float, optionalLower bound factor of sigma clipping. Default is 4.
high: float, optionalUpper bound factor of sigma clipping. Default is 4.
Returns
clipped: ndarrayInput array with clipped elements removed.
lower: floatLower threshold value use for clipping.
upper: floatUpper threshold value use for clipping.
Notes
This function iteratively removes observations. Once observations are removed, they are not re-added in subsequent iterations. Consequently, although it is often the case that clipped is identical to a[(a >= lower) & (a <= upper)], this property is not guaranteed to be satisfied; clipped may have fewer elements.
Array API Standard Support
sigmaclip 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 ⚠️ no JIT ⚠️ no JIT Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy.stats import sigmaclip a = np.concatenate((np.linspace(9.5, 10.5, 31), np.linspace(0, 20, 5))) fact = 1.5 c, low, upp = sigmaclip(a, fact, fact)✓
c c.var(), c.std() low, c.mean() - fact*c.std(), c.min() upp, c.mean() + fact*c.std(), c.max()✗
a = np.concatenate((np.linspace(9.5, 10.5, 11), np.linspace(-100, -50, 3))) c, low, upp = sigmaclip(a, 1.8, 1.8)✓
(c == np.linspace(9.5, 10.5, 11)).all()
✗Aliases
-
scipy.stats.sigmaclip