How to create a normal distribution in pytorch

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

    You can create your distribution like described here in the docs. In your case this should be the correct call, including sampling from the created distribution:

    from torch.distributions import normal
    
    m = normal.Normal(4.0, 0.5)
    s = m.sample()
    

    If you want to get a sample of a certain size/shape, you can pass it to sample(), for example

    s = m.sample([5, 5])
    

    for a 5x5-Tensor.

提交回复
热议问题