code: def regress_components( data, components, remove_mean=True ):
      
      timepoints = data.shape[0]
      betas = np.linalg.pinv(components).dot(data)
      if remove_mean:
          datahat = components.dot(betas)
      else:  # disregard the first layer of X, which is degree 0
          datahat = components[:, 1:].dot(betas[1:, ...])
      regressed_data = data - datahat
      return regressed_data
docs: Returns data with components regressed out.
      :param bool remove_mean: whether or not demean data (i.e. degree 0),
      :param int axis: numpy array axes along which regression is performed