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 print(z.numpy()) # [[-2.-2.j -2.-1.j -2.+0.j -2.+1.j] # [-1.-2.j -1.-1.j -1.+0.j -1.+1.j] # [ 0.-2.j 0.-1.j 0.+0.j 0.+1.j] # [ 1.-2.j 1.-1.j 1.+0.j 1.+1.j]] theta = paddle.angle(z) print(theta.numpy()) # [[-2.3561945 -2.6779451 3.1415927 2.6779451] # [-2.0344439 -2.3561945 3.1415927 2.3561945] # [-1.5707964 -1.5707964 0. 1.5707964] # [-1.1071488 -0.7853982 0. 0.7853982]]