Rate this Page

torch.reciprocal#

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

Returns a new tensor with the reciprocal of the elements ofinput

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

Note

Unlike NumPy’s reciprocal, torch.reciprocal supports integral inputs. Integralinputs to reciprocal are automaticallypromoted tothe default scalar type.

Parameters:

input (Tensor) – the input tensor.

Keyword Arguments:

out (Tensor,optional) – the output tensor.

Example:

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