torch.Tensor.random_
-
Tensor.random_(from=0, to=None, *, generator=None) → Tensor
用离散均匀分布填充 self
张量中的数字。如果未指定,值通常仅受限于 self
张量的数据类型。然而,对于浮点类型,如果未指定,范围将是 [0, 2^mantissa]
以确保每个值都是可表示的。例如,torch.tensor(1, dtype=torch.double).random_() 将在 [0, 2^53]
上是均匀分布的。