code: def mad(arr):
      
      arr = np.ma.array(arr).compressed() # should be faster to not use masked arrays.
      med = np.median(arr)
      return np.median(np.abs(arr - med))
docs: Median Absolute Deviation: a "Robust" version of standard deviation.
          Indices variabililty of the sample.
          https://en.wikipedia.org/wiki/Median_absolute_deviation