Shortcuts

torch.sign

torch.sign(input, *, out=None) Tensor

Returns a new tensor with the signs of the elements of input.

outi=sgn(inputi)\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})
Parameters:

input (Tensor) – the input tensor.

Keyword Arguments:

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000,  0.0000,  2.3000])
>>> torch.sign(a)
tensor([ 1., -1.,  0.,  1.])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources