code: def to_new(self, data, k=None, sigma=None, return_distances=False):
          
          n_samples = data.shape[0]
          n_reference_samples = self.n_samples
  
          if k is None:
              k = self.k
          elif k >= n_reference_samples:
              raise ValueError(
                  "`k` (%d) cannot be larger than the number of reference "
                  "samples (%d)." % (k, self.n_samples)
              )
  
          if sigma is None:
              sigma = self.sigma
  
          # Find nearest neighbors and the distances to the new points
          neighbors, distances = self.knn_index.query(data, k)
  
          # Compute asymmetric pairwise input similarities
          conditional_P = np.exp(-distances ** 2 / (2 * sigma ** 2))
  
          # Convert weights to probabilities
          conditional_P /= np.sum(conditional_P, axis=1)[:, np.newaxis]
  
          P = sp.csr_matrix(
              (conditional_P.ravel(), neighbors.ravel(), range(0, n_samples * k + 1, k)),
              shape=(n_samples, n_reference_samples),
          )
  
          if return_distances:
              return P, neighbors, distances
  
          return P
docs: Compute the affinities of new samples to the initial samples.
  
          This is necessary for embedding new data points into an existing
          embedding.
  
          Parameters
          ----------
          data: np.ndarray
              The data points to be added to the existing embedding.
  
          k: int
              The number of nearest neighbors to consider for each kernel.
  
          sigma: float
              The bandwidth to use for the Gaussian kernels in the ambient space.
  
          return_distances: bool
              If needed, the function can return the indices of the nearest
              neighbors and their corresponding distances.
  
          Returns
          -------
          P: array_like
              An :math:`N \\times M` affinity matrix expressing interactions
              between :math:`N` new data points the initial :math:`M` data
              samples.
  
          indices: np.ndarray
              Returned if ``return_distances=True``. The indices of the :math:`k`
              nearest neighbors in the existing embedding for every new data
              point.
  
          distances: np.ndarray
              Returned if ``return_distances=True``. The distances to the
              :math:`k` nearest neighbors in the existing embedding for every new
              data point.