I want to create a random normal distribution in pytorch and mean and std are 4, 0.5 respectively. I didn't find a API for it. Anyone knows? Thanks very much.
You can easily use torch.Tensor.normal_() method.
Let's create a matrix Z (a 1d tensor) of dimension 1 × 5
, filled with random elements samples from the normal distribution parameterized by mean = 4
and std = 0.5
.
torch.empty(5).normal_(mean=4,std=0.5)
Result:
tensor([4.1450, 4.0104, 4.0228, 4.4689, 3.7810])