mercredi 22 janvier 2020

Why randn doesn't always have a mean of 0 and variance of 1?

For the PyTorch.randn() method the documentation says:

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).

So here is an example tensor:

x = torch.randn(4,3)
tensor([[-0.6569, -0.7337, -0.0028],
        [-0.3938,  0.3223,  0.0497],
        [ 0.0129, -2.7546, -2.2488],
        [ 1.6754, -0.1497,  1.8202]])

When I print the mean:

x.mean()
tensor(-0.2550)

When I print the standard deviation:

x.std()
tensor(1.3225)

So why isn't the mean 0 and the standard deviation 1?

Bonus question: How do I generate a random tensor that always has a mean of 0?




Aucun commentaire:

Enregistrer un commentaire