It seems scipy once provided a function mad to calculate the mean absolute deviation for a set of numbers:
mad
http://projects.scipy.org/scipy/browser/trunk
I'm using:
from math import fabs a = [1, 1, 2, 2, 4, 6, 9] median = sorted(a)[len(a)//2] for b in a: mad = fabs(b - median) print b,mad