评价此页

torch.Tensor.bernoulli_#

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

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

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

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

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