def _krandinit(data, k):
def init_rank1(data):<EOL><INDENT>mu = np.mean(data)<EOL>cov = np.cov(data)<EOL>x = np.random.randn(k)<EOL>x *= np.sqrt(cov)<EOL>x += mu<EOL>return x<EOL><DEDENT>def init_rankn(data):<EOL><INDENT>mu = np.mean(data, <NUM_LIT:0>)<EOL>cov = np.atleast_2d(np.cov(data, rowvar=<NUM_LIT:0>))<EOL>x = np.random.randn(k, mu.size)<EOL>x = np.dot(x, np.linalg.cholesky(cov).T) + mu<EOL>return x<EOL><DEDENT>nd = np.ndim(data)<EOL>if nd == <NUM_LIT:1>:<EOL><INDENT>return init_rank1(data)<EOL><DEDENT>else:<EOL><INDENT>return init_rankn(data)<EOL><DEDENT>
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.