Gaussian distribution

Hi,

I would like to create the random Gaussian distribution with mean = 0 and std = 0.1 but I couldn’t figure out how I can do it in pyTorch. In Tensorflow I can create random Gaussian distribution with specifying the mean and std in one line but in pyTorch no idea.

In Tensorflow:

z = tf.zeros((10,10))
noise = tf.random_normal(shape = z.get_shape(), mean = 0.0, stddev = 0.1, dtype = tf.float32)

Can anyone translate this line for me in pyTorch or help me? it’s 2 hours I am trying to translate this code to pyTorch but couldn’t.

Thanks,

You can yse torch.randn() and then scale the generated random numbers to match the desired stdded. torch.randn will generated Gaussian Normal Distribution (mean=0, and stddev=1), so by scaling them with 0.1 you can adjust the stddev.

>>> x = torch.randn(10000)
>>> x.std()
tensor(1.0039)
>>> x2 = x / 10
>>> x2.std()
tensor(0.1004)