How to get a uniform distribution in a range [r1,r2] in PyTorch?

前端 未结 8 1657
深忆病人
深忆病人 2021-02-05 01:49

The question says it all. I want to get a 2-D torch.Tensor with size [a,b] filled with values from a uniform distribution (in range [r1,r2]

8条回答
  •  佛祖请我去吃肉
    2021-02-05 02:16

    For those who are frustratingly bashing their keyboard yelling "why isn't this working." as I was... note the underscore behind the word uniform.

    torch.FloatTensor(a, b).uniform_(r1, r2)
                                   ^ here
    

提交回复
热议问题