human
Complete this python program:
def _krandinit(data, k):
assistant
#Here is the Python program you requested.

    """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.
    """
    def init_rank1(data):
        mu = np.mean(data)
        cov = np.cov(data)
        x = np.random.randn(k)
        x *= np.sqrt(cov)
        x += mu
        return x
    def init_rankn(data):
        mu = np.mean(data, 0)
        cov = np.atleast_2d(np.cov(data, rowvar=0))
        x = np.random.randn(k, mu.size)
        x = (np.dot(x, np.linalg.cholesky(cov).T) + mu)
        return x
    def init_rank_def(data):
        mu = np.mean(data, axis=0)
        (_, 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 = (np.dot(x, sVh) + mu)
        return x
    nd = np.ndim(data)
    if (nd == 1):
        return init_rank1(data)
    elif (data.shape[1] > data.shape[0]):
        return init_rank_def(data)
    else:
        return init_rankn(data)