angle

paddle. angle ( x: Tensor, name: str | None = None ) Tensor [source]

Element-wise angle of complex numbers. For non-negative real numbers, the angle is 0 while for negative real numbers, the angle is \(\pi\), and NaNs are propagated..

Equation:
\[angle(x)=arctan2(x.imag, x.real)\]
Parameters
  • x (Tensor) – An N-D Tensor, the data type is complex64, complex128, or float32, float64 .

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.

Returns

An N-D Tensor of real data type with the same precision as that of x’s data type.

Return type

Tensor

Examples

>>> import paddle

>>> x = paddle.to_tensor([-2, -1, 0, 1]).unsqueeze(-1).astype('float32')
>>> y = paddle.to_tensor([-2, -1, 0, 1]).astype('float32')
>>> z = x + 1j * y
>>> z
Tensor(shape=[4, 4], dtype=complex64, place=Place(cpu), stop_gradient=True,
[[(-2.00000000-2.00000000j), (-2.00000000-1.00000000j),
  (-2.00000000+0.00000000j), (-2.00000000+1.00000000j)],
 [(-1.00000000-2.00000000j), (-1.00000000-1.00000000j),
  (-1.00000000+0.00000000j), (-1.00000000+1.00000000j)],
 [(0.00000000-2.00000000j) , (0.00000000-1.00000000j) ,
   (0.00000000+0.00000000j),  (0.00000000+1.00000000j)],
 [ (1.00000000-2.00000000j),  (1.00000000-1.00000000j),
   (1.00000000+0.00000000j),  (1.00000000+1.00000000j)]])

>>> theta = paddle.angle(z)
>>> theta
Tensor(shape=[4, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-2.35619450, -2.67794514,  3.14159274,  2.67794514],
 [-2.03444386, -2.35619450,  3.14159274,  2.35619450],
 [-1.57079637, -1.57079637,  0.        ,  1.57079637],
 [-1.10714877, -0.78539819,  0.        ,  0.78539819]])