How to create a normal distribution in pytorch

后端 未结 6 1739
别跟我提以往
别跟我提以往 2021-01-03 22:48

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.

6条回答
  •  感情败类
    2021-01-03 23:19

    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])
    

提交回复
热议问题