How to create multiple MultiVariateNormal at one time

If I call

MultivariateNormal(torch.randn(2), torch.eye(2))

I got one MultivariateNormal distribution,

If I want to create 100 of them; the means are in tensor of shape (100, 2), the covariance matrices are in a tensor of shape (100, 2, 2), essentially the batch shape is 100 and event shape is 2, how could I create these 100 MultivariateNormal distribution without a loop? Thanks!

@wwd some kind of looping will have to be done if you want to use this function as each distribution is separate from the other. However you can parallelize without using direct loops


loc = torch.randn(100, 2)
cov = torch.zeros(100, 2, 2)
cov[:, 0, 0] = 1
cov[:, 1, 1] = 1
def get_distribution(x):
    return torch.distributions.MultivariateNormal(loc[x], cov[x])
list(map(get_distribution, range(100)))