code: def barycenter_weights(X, Y, indices, reg=1e-3):
      """Compute barycenter weights of X from Y along the first axis
  
      We estimate the weights to assign to each point in Y[indices] to recover
      the point X[i]. The barycenter weights sum to 1.
  
      Parameters
      ----------
      X : array-like, shape (n_samples, n_dim)
  
      Y : array-like, shape (n_samples, n_dim)
  
      indices : array-like, shape (n_samples, n_dim)
              Indices of the points in Y used to compute the barycenter
  
      reg : float, default=1e-3
          Amount of regularization to add for the problem to be
          well-posed in the case of n_neighbors > n_dim
  
      Returns
      -------
      B : array-like, shape (n_samples, n_neighbors)
  
      Notes
      -----
      See developers note for more information.
      """
      X = check_array(X, dtype=FLOAT_DTYPES)
      Y = check_array(Y, dtype=FLOAT_DTYPES)
      indices = check_array(indices, dtype=int)
  
      n_samples, n_neighbors = indices.shape
      assert X.shape[0] == n_samples
  
      B = np.empty((n_samples, n_neighbors), dtype=X.dtype)
      v = np.ones(n_neighbors, dtype=X.dtype)
  
      # this might raise a LinalgError if G is singular and has trace
      # zero
      for i, ind in enumerate(indices):
          A = Y[ind]
          C = A - X[i]  # broadcasting
          G = np.dot(C, C.T)
          trace = np.trace(G)
          if trace > 0:
              R = reg * trace
          else:
              R = reg
          G.flat[:: n_neighbors + 1] += R
          w = solve(G, v, assume_a="pos")
          B[i, :] = w / np.sum(w)
      return B
  
imports: from numbers import Integral, Real
  import numpy
  from scipy.linalg import eigh, qr, solve, svd
  from scipy.sparse import csr_matrix, eye
  from scipy.sparse.linalg import eigsh
  from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin, _fit_context, _UnstableArchMixin
  from ..neighbors import NearestNeighbors
  from ..utils import check_array, check_random_state
  from ..utils._arpack import _init_arpack_v0
  from ..utils._param_validation import Interval, StrOptions
  from ..utils.extmath import stable_cumsum
  from ..utils.validation import FLOAT_DTYPES, check_is_fitted
label_desc: Use image node_id 1 for calling a global function with example usage: barycenter_weights(X, Y, indices, reg) and returns: B