code: def _k_init(
      X, n_clusters, x_squared_norms, random_state, n_local_trials=None
  ):
      """Init n_clusters seeds according to k-means++
  
      Parameters
      -----------
      X: array or sparse matrix, shape (n_samples, n_features)
          The data to pick seeds for. To avoid memory copy, the input data
          should be double precision (dtype=np.float64).
  
      n_clusters: integer
          The number of seeds to choose
  
      x_squared_norms: array, shape (n_samples,)
          Squared Euclidean norm of each data point.
  
      random_state: numpy.RandomState
          The generator used to initialize the centers.
  
      n_local_trials: integer, optional
          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.
  
      Notes
      -----
      Selects initial cluster centers for k-mean clustering in a smart way
      to speed up convergence. see: Arthur, D. and Vassilvitskii, S.
      "k-means++: the advantages of careful seeding". ACM-SIAM symposium
      on Discrete algorithms. 2007
  
      Version ported from http://www.stanford.edu/~darthur/kMeansppTest.zip,
      which is the implementation used in the aforementioned paper.
      """
      n_samples, n_features = X.shape
  
      centers = np.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 sp.issparse(X):
          centers[0] = X[center_id].toarray()
      else:
          centers[0] = X[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.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 = np.searchsorted(
              closest_dist_sq.cumsum(), rand_vals
          )
  
          # Compute distances to center candidates
          distance_to_candidates = euclidean_distances(
              X[candidate_ids],
              X,
              Y_norm_squared=x_squared_norms,
              squared=True,
          )
  
          # Decide which candidate is the best
          best_candidate = None
          best_pot = None
          best_dist_sq = None
          for trial in range(n_local_trials):
              # Compute potential when including center candidate
              new_dist_sq = np.minimum(
                  closest_dist_sq, distance_to_candidates[trial]
              )
              new_pot = new_dist_sq.sum()
  
              # Store result if it is the best local trial so far
              if (best_candidate is None) or (new_pot < best_pot):
                  best_candidate = candidate_ids[trial]
                  best_pot = new_pot
                  best_dist_sq = new_dist_sq
  
          # 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]
          current_pot = best_pot
          closest_dist_sq = best_dist_sq
  
      return centers
  
imports: import warnings
  import numpy
  import scipy.sparse
  from ..base import BaseEstimator, ClusterMixin, TransformerMixin
  from ..metrics.pairwise import euclidean_distances
  from ..metrics.pairwise import pairwise_distances_argmin_min
  from ..utils.extmath import row_norms, squared_norm
  from ..utils.sparsefuncs_fast import assign_rows_csr
  from ..utils.sparsefuncs import mean_variance_axis
  from ..utils.fixes import astype
  from ..utils import check_array
  from ..utils import check_random_state
  from ..utils import as_float_array
  from ..utils import gen_batches
  from ..utils.validation import check_is_fitted
  from ..utils.validation import FLOAT_DTYPES
  from ..utils.random import choice
  from ..externals.joblib import Parallel
  from ..externals.joblib import delayed
  from ..externals.six import string_types
  from .None import _k_means
  from ._k_means_elkan import k_means_elkan
label_desc: Use image node_id 1 for calling a global function with example usage: _k_init(X, n_clusters, x_squared_norms, random_state, n_local_trials) and returns: centers