How to create a normal distribution in pytorch

后端 未结 6 1741
别跟我提以往
别跟我提以往 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:16

    For all distribution see: https://pytorch.org/docs/stable/distributions.html#

    click on right menu to jump to normal (or search in the docs).

    An example code:

    import torch
    
    num_samples = 3
    Din = 1
    mu, std = 0, 1
    x = torch.distributions.normal.Normal(loc=mu, scale=std).sample((num_samples, Din))
    
    print(x)
    

    For details on torch distributions (with emphasis on uniform) see my SO answer here: https://stackoverflow.com/a/62919760/1601580

提交回复
热议问题