torch.Tensor.bernoulli_

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

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

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

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

参见 bernoulli()torch.bernoulli()