Shortcuts

torch.Tensor.bernoulli_

Tensor.bernoulli_(p=0.5, *, generator=None) 张量

用从 Bernoulli(p)\text{Bernoulli}(\texttt{p})独立采样的值填充self的每个位置。self可以具有整数 dtype

p 应该是一个标量或包含概率的张量,用于绘制二进制随机数。

如果它是一个张量,ith\text{i}^{th}元素将被设置为一个从Bernoulli(p_tensor[i])\text{Bernoulli}(\texttt{p\_tensor[i]})采样的值。在这种情况下,p必须具有浮点dtype

另请参阅 bernoulli()torch.bernoulli()