code: def compute_average_regress(x, idx_chan):
      
      if x.ndim != 2:
          raise ValueError(f'The number of dimensions must be 2, not {x.ndim}')
  
      x = moveaxis(x, idx_chan, 0)  # move axis to the front
      avg = mean(x, axis=0)
  
      x_o = []
      for i in range(x.shape[0]):
          r = lstsq(avg[:, None], x[i, :][:, None], rcond=0)[0]
          x_o.append(
              x[i, :] - r[0, 0] * avg
              )
      return moveaxis(asarray(x_o), 0, idx_chan)
docs: Take the mean across channels and regress out the mean from each channel
  
      Parameters
      ----------
      x : ndarray
          2d array with channels on one dimension
      idx_chan:
          which axis contains channels
  
      Returns
      -------
      ndarray
          same as x, but with the mean being regressed out