python np.random.multivariate_normal

import numpy as np

mean = [0, 0]
cov = [[1, 0], [0, 5]]

import matplotlib.pyplot as plt
x, y = np.random.multivariate_normal(mean, cov, 100).T
plt.plot(x, y, 'x')
plt.axis('equal')
plt.show()

Parameters:
mean : 1-D array_like, of length N
Mean of the N-dimensional distribution.

cov : 2-D array_like, of shape (N, N)
Covariance matrix of the distribution. It must be symmetric and positive-semidefinite for proper sampling.

size : int or tuple of ints, optional
Given a shape of, for example, (m,n,k), mnk samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is (m,n,k,N). If no shape is specified, a single (N-D) sample is returned.

check_valid : { ‘warn’, ‘raise’, ‘ignore’ }, optional
Behavior when the covariance matrix is not positive semidefinite.

tol : float, optional
Tolerance when checking the singular values in covariance matrix.

Returns:
out : ndarray
The drawn samples, of shape size, if that was provided. If not, the shape is (N,).

In other words, each entry out[i,j,…,:] is an N-dimensional value drawn from the distribution.
python np.random.multivariate_normal
http://www.waitingfy.com/archives/5019

猜你喜欢

转载自blog.csdn.net/fox64194167/article/details/82904685