code: def _init_centroids(
      X,
      k,
      init,
      random_state=None,
      x_squared_norms=None,
      init_size=None,
  ):
      """Compute the initial centroids
  
      Parameters
      ----------
  
      X: array, shape (n_samples, n_features)
  
      k: int
          number of centroids
  
      init: {'k-means++', 'random' or ndarray or callable} optional
          Method for initialization
  
      random_state: integer or numpy.RandomState, optional
          The generator used to initialize the centers. If an integer is
          given, it fixes the seed. Defaults to the global numpy random
          number generator.
  
      x_squared_norms:  array, shape (n_samples,), optional
          Squared euclidean norm of each data point. Pass it if you have it at
          hands already to avoid it being recomputed here. Default: None
  
      init_size : int, optional
          Number of samples to randomly sample for speeding up the
          initialization (sometimes at the expense of accuracy): the
          only algorithm is initialized by running a batch KMeans on a
          random subset of the data. This needs to be larger than k.
  
      Returns
      -------
      centers: array, shape(k, n_features)
      """
      random_state = check_random_state(random_state)
      n_samples = X.shape[0]
  
      if x_squared_norms is None:
          x_squared_norms = row_norms(X, squared=True)
  
      if init_size is not None and init_size < n_samples:
          if init_size < k:
              warnings.warn(
                  "init_size=%d should be larger than k=%d. "
                  "Setting it to 3*k" % (init_size, k),
                  RuntimeWarning,
                  stacklevel=2,
              )
              init_size = 3 * k
          init_indices = random_state.randint(0, n_samples, init_size)
          X = X[init_indices]
          x_squared_norms = x_squared_norms[init_indices]
          n_samples = X.shape[0]
      elif n_samples < k:
          raise ValueError(
              "n_samples=%d should be larger than k=%d" % (n_samples, k)
          )
  
      if isinstance(init, string_types) and init == "k-means++":
          centers = _k_init(
              X,
              k,
              random_state=random_state,
              x_squared_norms=x_squared_norms,
          )
      elif isinstance(init, string_types) and init == "random":
          seeds = random_state.permutation(n_samples)[:k]
          centers = X[seeds]
      elif hasattr(init, "__array__"):
          # ensure that the centers have the same dtype as X
          # this is a requirement of fused types of cython
          centers = np.array(init, dtype=X.dtype)
      elif callable(init):
          centers = init(X, k, random_state=random_state)
          centers = np.asarray(centers, dtype=X.dtype)
      else:
          raise ValueError(
              "the init parameter for the k-means should "
              "be 'k-means++' or 'random' or an ndarray, "
              "'%s' (type '%s') was passed." % (init, type(init))
          )
  
      if sp.issparse(centers):
          centers = centers.toarray()
  
      _validate_center_shape(X, k, centers)
      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 9 for calling a global function with example usage: _init_centroids(X, k, init, random_state, x_squared_norms, init_size) and returns: centers