angle¶
- paddle. angle ( x, name=None ) [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\).
- 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, optional) – Name for the operation (optional, default is None). For more information, please refer to 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-2j), (-2-1j), (-2+0j), (-2+1j)], [(-1-2j), (-1-1j), (-1+0j), (-1+1j)], [-2j , -1j , 0j , 1j ], [ (1-2j), (1-1j), (1+0j), (1+1j)]]) >>> 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]])