快捷方式

torch.Tensor.bernoulli_

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

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

p 應該是一個標量或一個包含用於抽取二元隨機數的機率的張量。

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

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

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源