Table of Contents
Shortcuts

# torch.sgn

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

  This function is an extension of torch.sign() to complex tensors. It computes a new tensor whose elements have the same angles as the corresponding elements of `input` and absolute values (i.e. magnitudes) of one for complex tensors and is equivalent to torch.sign() for non-complex tensors.

  out i={0∣input i∣==0 input i∣input i∣otherwise\text{out}_{i} = \begin{cases} 0 & |\text{{input}}_i| == 0 \\ \frac{{\text{{input}}_i}}{|{\text{{input}}_i}|} & \text{otherwise} \end{cases} out i​={0∣input i​∣input i​​​∣input i​∣==0 otherwise​
  Parameters:

    input (Tensor) – the input tensor.

  Keyword Arguments:

    out (Tensor, optional) – the output tensor.

  Example:

      >>> t = torch.tensor([3+4j, 7-24j, 0, 1+2j])
      >>> t.sgn()
      tensor([0.6000+0.8000j, 0.2800-0.9600j, 0.0000+0.0000j, 0.4472+0.8944j])

## 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

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.