快捷键

torch.Tensor.bernoulli_

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

用独立样本填充 self 的每个位置。 self 可以是整数 dtype

p 应为一个标量或包含用于抽取二进制随机数的概率的 tensor。

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

参见 bernoulli()torch.bernoulli()


© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源