median_absolute_deviation¶
-
astropy.stats.
median_absolute_deviation
(a, axis=None)[source] [edit on github]¶ Calculate the median absolute deviation (MAD).
The MAD is defined as
median(abs(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 MADs are computed. The default (
None
) is to compute the MAD of the flattened array.Returns: mad : float or
ndarray
The median absolute deviation of the input array. If
axis
isNone
then a scalar will be returned, otherwise andarray
will be returned.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.RandomState(12345) >>> from numpy.random import randn >>> mad = median_absolute_deviation(rand.randn(1000)) >>> print(mad) 0.65244241428454486