code: def center_gram(gram, unbiased=False):
      """Center a symmetric Gram matrix.
  
      This is equvialent to centering the (possibly infinite-dimensional) features
      induced by the kernel before computing the Gram matrix.
  
      Args:
        gram: A num_examples x num_examples symmetric matrix.
        unbiased: Whether to adjust the Gram matrix in order to compute an unbiased
          estimate of HSIC. Note that this estimator may be negative.
  
      Returns:
        A symmetric matrix with centered columns and rows.
      """
      if not np.allclose(gram, gram.T):
          raise ValueError("Input must be a symmetric matrix.")
      gram = gram.copy()
  
      if unbiased:
          # This formulation of the U-statistic, from Szekely, G. J., & Rizzo, M.
          # L. (2014). Partial distance correlation with methods for dissimilarities.
          # The Annals of Statistics, 42(6), 2382-2412, seems to be more numerically
          # stable than the alternative from Song et al. (2007).
          n = gram.shape[0]
          np.fill_diagonal(gram, 0)
          means = np.sum(gram, 0, dtype=np.float64) / (n - 2)
          means -= np.sum(means) / (2 * (n - 1))
          gram -= means[:, None]
          gram -= means[None, :]
          np.fill_diagonal(gram, 0)
      else:
          means = np.mean(gram, 0, dtype=np.float64)
          means -= np.mean(means) / 2
          gram -= means[:, None]
          gram -= means[None, :]
  
      return gram
  
imports: import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: center_gram(gram, unbiased) and returns: gram