code: def _kmeans_plusplus(
      X,
      n_clusters,
      x_squared_norms,
      sample_weight,
      random_state,
      n_local_trials=None,
  ):
      """Computational component for initialization of n_clusters by
      k-means++. Prior validation of data is assumed.
  
      Parameters
      ----------
      X : {ndarray, sparse matrix} of shape (n_samples, n_features)
          The data to pick seeds for.
  
      n_clusters : int
          The number of seeds to choose.
  
      sample_weight : ndarray of shape (n_samples,)
          The weights for each observation in `X`.
  
      x_squared_norms : ndarray of shape (n_samples,)
          Squared Euclidean norm of each data point.
  
      random_state : RandomState instance
          The generator used to initialize the centers.
          See :term:`Glossary <random_state>`.
  
      n_local_trials : int, default=None
          The number of seeding trials for each center (except the first),
          of which the one reducing inertia the most is greedily chosen.
          Set to None to make the number of trials depend logarithmically
          on the number of seeds (2+log(k)); this is the default.
  
      Returns
      -------
      centers : ndarray of shape (n_clusters, n_features)
          The initial centers for k-means.
  
      indices : ndarray of shape (n_clusters,)
          The index location of the chosen centers in the data array X. For a
          given index and center, X[index] = center.
      """
      n_samples, n_features = X.shape
  
      centers = np.empty((n_clusters, n_features), dtype=X.dtype)
  
      # Set the number of local seeding trials if none is given
      if n_local_trials is None:
          # This is what Arthur/Vassilvitskii tried, but did not report
          # specific results for other than mentioning in the conclusion
          # that it helped.
          n_local_trials = 2 + int(np.log(n_clusters))
  
      # Pick first center randomly and track index of point
      center_id = random_state.choice(
          n_samples, p=sample_weight / sample_weight.sum()
      )
      indices = np.full(n_clusters, -1, dtype=int)
      if sp.issparse(X):
          centers[0] = X[center_id].toarray()
      else:
          centers[0] = X[center_id]
      indices[0] = center_id
  
      # Initialize list of closest distances and calculate current potential
      closest_dist_sq = _euclidean_distances(
          centers[0, np.newaxis],
          X,
          Y_norm_squared=x_squared_norms,
          squared=True,
      )
      current_pot = closest_dist_sq @ sample_weight
  
      # Pick the remaining n_clusters-1 points
      for c in range(1, n_clusters):
          # Choose center candidates by sampling with probability proportional
          # to the squared distance to the closest existing center
          rand_vals = (
              random_state.uniform(size=n_local_trials) * current_pot
          )
          candidate_ids = np.searchsorted(
              stable_cumsum(sample_weight * closest_dist_sq), rand_vals
          )
          # XXX: numerical imprecision can result in a candidate_id out of range
          np.clip(
              candidate_ids,
              None,
              closest_dist_sq.size - 1,
              out=candidate_ids,
          )
  
          # Compute distances to center candidates
          distance_to_candidates = _euclidean_distances(
              X[candidate_ids],
              X,
              Y_norm_squared=x_squared_norms,
              squared=True,
          )
  
          # update closest distances squared and potential for each candidate
          np.minimum(
              closest_dist_sq,
              distance_to_candidates,
              out=distance_to_candidates,
          )
          candidates_pot = (
              distance_to_candidates @ sample_weight.reshape(-1, 1)
          )
  
          # Decide which candidate is the best
          best_candidate = np.argmin(candidates_pot)
          current_pot = candidates_pot[best_candidate]
          closest_dist_sq = distance_to_candidates[best_candidate]
          best_candidate = candidate_ids[best_candidate]
  
          # Permanently add best center candidate found in local tries
          if sp.issparse(X):
              centers[c] = X[best_candidate].toarray()
          else:
              centers[c] = X[best_candidate]
          indices[c] = best_candidate
  
      return centers, indices
  
imports: import warnings
  from abc import ABC, abstractmethod
  from numbers import Integral, Real
  import numpy
  import scipy.sparse
  from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, ClusterMixin, TransformerMixin, _fit_context
  from ..exceptions import ConvergenceWarning
  from ..metrics.pairwise import _euclidean_distances, euclidean_distances
  from ..utils import check_array, check_random_state
  from ..utils._openmp_helpers import _openmp_effective_n_threads
  from ..utils._param_validation import Hidden, Interval, StrOptions, validate_params
  from ..utils.extmath import row_norms, stable_cumsum
  from ..utils.fixes import threadpool_info, threadpool_limits
  from ..utils.sparsefuncs import mean_variance_axis
  from ..utils.sparsefuncs_fast import assign_rows_csr
  from ..utils.validation import _check_sample_weight, _is_arraylike_not_scalar, check_is_fitted
  from ._k_means_common import CHUNK_SIZE, _inertia_dense, _inertia_sparse, _is_same_clustering
  from ._k_means_elkan import elkan_iter_chunked_dense, elkan_iter_chunked_sparse, init_bounds_dense, init_bounds_sparse
  from ._k_means_lloyd import lloyd_iter_chunked_dense, lloyd_iter_chunked_sparse
  from ._k_means_minibatch import _minibatch_update_dense, _minibatch_update_sparse
label_desc: Use image node_id 2 for calling a global function with example usage: _kmeans_plusplus(X, n_clusters, x_squared_norms, sample_weight, random_state, n_local_trials) and returns: centers,  indices