mad_std

astropy.stats.mad_std(data, axis=None)[source] [edit on github]

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 : array-like

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

axis : int, optional

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

Returns:

mad_std : 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.

Examples

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