評價此頁

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()