code: def _krandinit(data, k):
      """Returns k samples of a random variable which parameters depend on data.
  
      More precisely, it returns k observations sampled from a Gaussian random
      variable which mean and covariances are the one estimated from data.
  
      Parameters
      ----------
      data : ndarray
          Expect a rank 1 or 2 array. Rank 1 are assumed to describe one
          dimensional data, rank 2 multidimensional data, in which case one
          row is one observation.
      k : int
          Number of samples to generate.
  
      Returns
      -------
      x : ndarray
          A 'k' by 'N' containing the initial centroids
  
      """
      mu = data.mean(axis=0)
  
      if data.ndim == 1:
          cov = np.cov(data)
          x = np.random.randn(k)
          x *= np.sqrt(cov)
      elif data.shape[1] > data.shape[0]:
          # initialize when the covariance matrix is rank deficient
          _, s, vh = np.linalg.svd(data - mu, full_matrices=False)
          x = np.random.randn(k, s.size)
          sVh = s[:, None] * vh / np.sqrt(data.shape[0] - 1)
          x = x.dot(sVh)
      else:
          cov = np.atleast_2d(np.cov(data, rowvar=False))
  
          # k rows, d cols (one row = one obs)
          # Generate k sample of a random variable ~ Gaussian(mu, cov)
          x = np.random.randn(k, mu.size)
          x = x.dot(np.linalg.cholesky(cov).T)
  
      x += mu
      return x
  
imports: from __future__ import division, print_function, absolute_import
  import warnings
  import numpy
  from collections import deque
  from scipy._lib._util import _asarray_validated
  from scipy._lib.six import xrange
  from scipy.spatial.distance import cdist
  from .None import _vq
label_desc: Use image node_id 7 for calling a global function with example usage: _krandinit(data, k) and returns: x