How to generate 2D gaussian with Python?

user103021 picture user103021 · Oct 7, 2011 · Viewed 89.5k times · Source

I can generate Gaussian data with random.gauss(mu, sigma) function, but how can I generate 2D gaussian? Is there any function like that?

Answer

NPE picture NPE · Oct 7, 2011

If you can use numpy, there is numpy.random.multivariate_normal(mean, cov[, size]).

For example, to get 10,000 2D samples:

np.random.multivariate_normal(mean, cov, 10000)

where mean.shape==(2,) and cov.shape==(2,2).