median_absolute_deviation#
- astropy.stats.median_absolute_deviation(data: ArrayLike, axis: int | tuple[int, ...] | None = None, func: Callable | None = None, ignore_nan: bool | None = False) float | NDArray[source]#
 Calculate the median absolute deviation (MAD).
The MAD is defined as
median(abs(a - median(a))).- Parameters:
 - datanumpy:array_like
 Input array or object that can be converted to an array.
- axis
python:None,python:int, orpython:tupleofpython:int, optional The axis or axes along which the MADs are computed. The default (
None) is to compute the MAD of the flattened array.- func
python:callable(), optional The function used to compute the median. Defaults to
numpy.ma.medianfor masked arrays, otherwise tonumpy.median.- ignore_nanbool, optional
 Ignore NaN values (treat them as if they are not in the array) when computing the median. This will use
numpy.ma.medianifaxisis specified, ornumpy.nanmedianifaxis==Noneand numpy’s version is >1.10 because nanmedian is slightly faster in this case.
- Returns:
 - mad
python:floatorndarray The median absolute deviation of the input array. If
axisisNonethen a scalar will be returned, otherwise andarraywill be returned.
- mad
 
See also
Examples
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.default_rng(12345) >>> from numpy.random import randn >>> mad = median_absolute_deviation(rand.standard_normal(1000)) >>> print(mad) 0.6829504282771885