评价此页

torch.Tensor.bernoulli_#

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

使用 Bernoulli(p)\text{Bernoulli}(\texttt{p}) 的独立样本填充 self 的每个位置。 selfdtype 可以是整型。

p 应该是一个标量或包含用于抽取二元随机数的概率的张量。

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

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