• 文档 >
  • torch >
  • torch.reciprocal
快捷键

torch.reciprocal

torch.reciprocal(input, *, out=None) → Tensor

返回 input 中每个元素倒数的新张量。

outi=1inputi\text{out}_{i} = \frac{1}{\text{input}_{i}}

注意

与 NumPy 的倒数不同,torch.reciprocal 支持整数输入。倒数函数的整数输入会自动提升为默认标量类型。

参数:

input (Tensor) – 输入张量。

关键字参数:

输出(张量,可选)- 输出张量。

示例:

>>> a = torch.randn(4)
>>> a
tensor([-0.4595, -2.1219, -1.4314,  0.7298])
>>> torch.reciprocal(a)
tensor([-2.1763, -0.4713, -0.6986,  1.3702])

© 版权所有 PyTorch 贡献者。

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

文档

PyTorch 的全面开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源