as_complex¶
- paddle. as_complex ( x: Tensor, name: str | None = None ) Tensor [source]
-
Transform a real tensor to a complex tensor.
The data type of the input tensor is ‘float32’ or ‘float64’, and the data type of the returned tensor is ‘complex64’ or ‘complex128’, respectively.
The shape of the input tensor is
(* ,2)
, (*
means arbitrary shape), i.e. the size of the last axis should be 2, which represent the real and imag part of a complex number. The shape of the returned tensor is(*,)
.The image below demonstrates the case that a real 3D-tensor with shape [2, 3, 2] is transformed into a complex 2D-tensor with shape [2, 3].
- Parameters
-
x (Tensor) – The input tensor. Data type is ‘float32’ or ‘float64’.
name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, The output. Data type is ‘complex64’ or ‘complex128’, with the same precision as the input.
Examples
>>> import paddle >>> x = paddle.arange(12, dtype=paddle.float32).reshape([2, 3, 2]) >>> y = paddle.as_complex(x) >>> print(y) Tensor(shape=[2, 3], dtype=complex64, place=Place(cpu), stop_gradient=True, [[1j , (2+3j) , (4+5j) ], [(6+7j) , (8+9j) , (10+11j)]])