astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v5.2.1 »
- Astrostatistics Tools (`astropy.stats`) »
- mad_std

# mad_std

astropy.stats.mad_std(data, axis=None, func=None, ignore_nan=False)

  Calculate a robust standard deviation using the median absolute deviation (MAD).

  The standard deviation estimator is given by:

  \[\sigma \approx \frac{\textrm{MAD}}{\Phi^{-1}(3/4)} \approx 1.4826 \ \textrm{MAD}\]

  where \(\Phi^{-1}(P)\) is the normal inverse cumulative distribution function evaluated at probability \(P = 3/4\).

  Parameters:
    data numpy:array_like

      Data array or object that can be converted to an array.

    axis `python:None`, `python:int`, or `python:tuple` of `python:int`, optional

      The axis or axes along which the robust standard deviations are computed. The default (`None`) is to compute the robust standard deviation of the flattened array.

    func `python:callable()`, optional

      The function used to compute the median. Defaults to `numpy.ma.median` for masked arrays, otherwise to `numpy.median`.

    ignore_nan bool

      Ignore NaN values (treat them as if they are not in the array) when computing the median. This will use `numpy.ma.median` if `axis` is specified, or `numpy.nanmedian` if `axis=None` and numpy’s version is >1.10 because nanmedian is slightly faster in this case.

  Returns:
    mad_std `python:float` or `ndarray`

      The robust standard deviation of the input data. If `axis` is `None` then a scalar will be returned, otherwise a `ndarray` will be returned.

  See also

  `biweight_midvariance`, `biweight_midcovariance`, `median_absolute_deviation`

  Examples

      >>> import numpy as np
      >>> from astropy.stats import mad_std
      >>> rand = np.random.default_rng(12345)
      >>> madstd = mad_std(rand.normal(5, 2, (100, 100)))
      >>> print(madstd)
      1.984147963351707