Skip to content

Instantly share code, notes, and snippets.

@tomr-stargazer
Last active August 29, 2015 13:59
Show Gist options
  • Save tomr-stargazer/10671360 to your computer and use it in GitHub Desktop.
Save tomr-stargazer/10671360 to your computer and use it in GitHub Desktop.
MAD
import numpy as np
def mad(x):
"""
Calculates the median absolute deviation of an array.
See http://en.wikipedia.org/wiki/Median_absolute_deviation
Parameters
----------
x : np.ndarray
Array of numbers
Returns
-------
mad : float
Median absolute deviation
"""
return np.median(np.abs(x - np.median(x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment