astropy:docs

median_absolute_deviation

astropy.stats.funcs.median_absolute_deviation(a, axis=None)[source] [edit on github]

Compute the median absolute deviation

Returns the median absolute deviation of the array elements. The MAD is defined as :math median( |a - median (a)| ).

Parameters :

a : array_like

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

axis : int, optional

Axis along which the medians are computed. The default (axis=None) is to compute the median along a flattened version of the array.

Returns :

median_absolute_deviation : ndarray

A new array holding the result. If the input contains integers, or floats of smaller precision than 64, then the output data-type is float64. Otherwise, the output data-type is the same as that of the input.

See also

median

Examples

This will generate random variates from a Gaussian distribution and return the median absolute deviation for that distribution:

>>> from astropy.stats import median_absolute_deviation
>>> from numpy.random import randn
>>> randvar = randn(10000)
>>> mad = median_absolute_deviation(randvar)