捷徑

torch.Tensor.bernoulli_

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

使用來自 Bernoulli(p)\text{Bernoulli}(\texttt{p}) 的獨立樣本填充 self 的每個位置。self 可以具有整數 dtype

p 應該是純量或張量,其中包含用於繪製二元隨機數的機率。

如果它是一個張量,則 ith\text{i}^{th} 元素 self 張量將被設定為從 Bernoulli(p_tensor[i])\text{Bernoulli}(\texttt{p\_tensor[i]}) 採樣的值。在這種情況下,p 必須具有浮點數 dtype

另請參閱 bernoulli()torch.bernoulli()

文件

取得 PyTorch 的完整開發者文件

檢視文件

教學

取得適合初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並取得問題解答

檢視資源