code: def mad(data):
      r
  
      return np.median(np.abs(data - np.median(data)))
docs: r"""Median absolute deviation
  
      This method calculates the median absolute deviation of the input data.
  
      Parameters
      ----------
      data : np.ndarray
          Input data array
  
      Returns
      -------
      float MAD value
  
      Examples
      --------
      >>> from modopt.math.stats import mad
      >>> a = np.arange(9).reshape(3, 3)
      >>> mad(a)
      2.0
  
      Notes
      -----
      The MAD is calculated as follows:
  
      .. math::
  
          \mathrm{MAD} = \mathrm{median}\left(|X_i - \mathrm{median}(X)|\right)