torch.reciprocal
- torch.reciprocal(input, *, out=None) → Tensor
-
返回一个新张量,其中包含
input
中每个元素的倒数。$\text{out}_{i} = \frac{1}{\text{input}_{i}}$注意
与 NumPy 的 reciprocal 不同,torch.reciprocal 支持整数输入。递归中的整数输入会自动 提升类型 到默认的标量类型。
示例:
>>> 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])