torch.polar(abs, angle, *, out=None)Tensor

Constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value abs and angle angle.

out=abscos(angle)+abssin(angle)j\text{out} = \text{abs} \cdot \cos(\text{angle}) + \text{abs} \cdot \sin(\text{angle}) \cdot j


torch.polar is similar to std::polar and does not compute the polar decomposition of a complex tensor like Python’s cmath.polar and SciPy’s linalg.polar do. The behavior of this function is undefined if abs is negative or NaN, or if angle is infinite.

  • abs (Tensor) – The absolute value the complex tensor. Must be float or double.

  • angle (Tensor) – The angle of the complex tensor. Must be same dtype as abs.

Keyword Arguments

out (Tensor) – If the inputs are torch.float32, must be torch.complex64. If the inputs are torch.float64, must be torch.complex128.


>>> import numpy as np
>>> abs = torch.tensor([1, 2], dtype=torch.float64)
>>> angle = torch.tensor([np.pi / 2, 5 * np.pi / 4], dtype=torch.float64)
>>> z = torch.polar(abs, angle)
>>> z
tensor([(0.0000+1.0000j), (-1.4142-1.4142j)], dtype=torch.complex128)


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources