astropy.stats.median_absolute_deviation(data, axis=None, func=None, ignore_nan=False)[source]

Calculate the median absolute deviation (MAD).

The MAD is defined as median(abs(a - median(a))).

data : array-like

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

axis : {int, sequence of int, None}, optional

Axis along which the MADs are computed. The default (None) is to compute the MAD of the flattened array.

func : callable, optional

The function used to compute the median. Defaults to 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 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.

mad : float or ndarray

The median absolute deviation of the input array. If axis is None then a scalar will be returned, otherwise a ndarray will be returned.

See also



Generate random variates from a Gaussian distribution and return the median absolute deviation for that distribution:

>>> import numpy as np
>>> from astropy.stats import median_absolute_deviation
>>> rand = np.random.RandomState(12345)
>>> from numpy.random import randn
>>> mad = median_absolute_deviation(rand.randn(1000))
>>> print(mad)