Correct way of using MultivariateNormal in pytorch

I am working on the first assignment. I am wondering what is an elegant way of computing a matrix of dimension N x M whose entries are coming from a Multivariate Gaussian. Each row of A is a vector of size M. To generate this vector, I have figured out I need to instantiate a MultivariateNormal and sample from it
dist = MultivariateNormal(torch.zeros(M), torch.eye(M))
vec1 = dist.sample()
How can I do this N times in a pythonic way without using a for loop?

OK. I actually figured it out myself from the documentation. There is a sample_shape parameter where we specify a tuple with the number of vectors we want sample_shape=(N,).

1 Like