7

I need to generate, say 2000 samples of 2D multivariate Gaussian distribution with mean [2;3] and covaraince C = [0.2 0; 0 0.3] in Julia. Is it possible to do it using MvNormal function from Distributions package?

Thanks in advance.

user5045
  • 231
  • 1
  • 4
  • 5
  • Is your question about the construction of the [MvNormal struct](https://juliastats.org/Distributions.jl/stable/multivariate/#Distributions.MvNormal), the use of the [rand function](https://juliastats.org/Distributions.jl/stable/multivariate/#Base.rand-Tuple{AbstractRNG,Distribution{Multivariate,S}%20where%20S%3C:ValueSupport}), or both? – PaSTE Apr 14 '21 at 19:23

1 Answers1

9

You can just straight up write down the code exactly as you describe

using Distributions
mean = [2.,3.]
C = [0.2 0; 0 0.3]
d = MvNormal(mean, C)
x = rand(d, 2000)

so, the answer to your question is yes.

Mikael Öhman
  • 2,294
  • 15
  • 21