code: def get_nondiag_weight(X):
      """Compute non-diagonality weights of a set of square matrices.
  
      Compute non-diagonality weights of a set of square matrices, following
      Eq(B.1) in [1]_.
  
      Parameters
      ----------
      X : ndarray, shape (..., n, n)
          The set of square matrices, at least 2D ndarray.
  
      Returns
      -------
      weights : ndarray, shape (...,)
          The non-diagonality weights for matrices.
  
      References
      ----------
      .. [1] `On the blind source separation of human electroencephalogram by
          approximate joint diagonalization of second order statistics
          <https://hal.archives-ouvertes.fr/hal-00343628>`_
          M. Congedo, C. Gouy-Pailler, C. Jutten. Clinical Neurophysiology,
          Elsevier, 2008, 119 (12), pp.2677-2686.
      """
      if not is_square(X):
          raise ValueError("Matrices must be square")
  
      X2 = X**2
      # sum of squared diagonal elements
      denom = np.trace(X2, axis1=-2, axis2=-1)
      # sum of squared off-diagonal elements
      num = np.sum(X2, axis=(-2, -1)) - denom
      weights = (1.0 / (X.shape[-1] - 1)) * (num / denom)
      return weights
  
imports: import warnings
  from functools import wraps
  import numpy
  from scipy.linalg import block_diag
  from scipy.stats import chi2
  from sklearn.covariance import oas, ledoit_wolf, fast_mcd
  from .distance import distance_mahalanobis
  from .test import is_square, is_real_type
label_desc: Use image node_id 21 for calling a global function with example usage: get_nondiag_weight(X) and returns: weights