code: def _kmeans_plus_plus_init(
      X,
      x_squared_norms,
      random_state,
      n_clusters: int,
      n_local_trials: int = None,
  ):
      n_samples, n_features = X.shape
  
      centers = mt.empty((n_clusters, n_features), dtype=X.dtype)
  
      assert (
          x_squared_norms is not None
      ), "x_squared_norms None in _k_init"
  
      # 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
      center_id = random_state.randint(n_samples)
      if X.issparse():  # pragma: no cover
          centers[0] = X[center_id].todense()
      else:
          centers[0] = X[center_id]
  
      # Initialize list of closest distances and calculate current potential
      closest_dist_sq = euclidean_distances(
          centers[0, mt.newaxis],
          X,
          Y_norm_squared=x_squared_norms,
          squared=True,
      )
      current_pot = closest_dist_sq.sum()
  
      # 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.random_sample(n_local_trials) * current_pot
          )
          candidate_ids = mt.searchsorted(
              closest_dist_sq.cumsum(), rand_vals
          )
          # XXX: numerical imprecision can result in a candidate_id out of range
          candidate_ids = mt.clip(
              candidate_ids, None, closest_dist_sq.size - 1
          )
  
          # 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
          distance_to_candidates = mt.minimum(
              closest_dist_sq, distance_to_candidates
          )
  
          candidates_pot = distance_to_candidates.sum(axis=1)
  
          # Decide which candidate is the best
          best_candidate = mt.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 X.issparse():  # pragma: no cover
              c_center = X[best_candidate].todense()
          else:
              c_center = X[best_candidate]
  
          centers[c] = c_center
  
      return centers
  
imports: import inspect
  import numpy
  from ...None import opcodes
  from ...None import tensor
  from ...core import OutputType, recursive_tile
  from ...core.operand import OperandStage
  from ...serialization.serializables import KeyField, Int32Field
  from ...tensor.array_utils import as_same_device, device
  from ...tensor.core import TensorOrder
  from ...tensor.random import RandomStateField
  from ...utils import has_unknown_shape
  from ..metrics import euclidean_distances
  from ..operands import LearnOperand, LearnOperandMixin
label_desc: Use image node_id 1 for calling a global function with example usage: _kmeans_plus_plus_init(X, x_squared_norms, random_state, n_clusters, n_local_trials) and returns: centers