as_real

paddle. as_real ( x, name=None ) [source]

Transform a complex tensor to a real tensor.

The data type of the input tensor is ‘complex64’ or ‘complex128’, and the data type of the returned tensor is ‘float32’ or ‘float64’, respectively.

When the shape of the input tensor is (*, ), (* means arbitary shape), the shape of the output tensor is (*, 2), i.e. the shape of the output is the shape of the input appended by an extra 2.

Parameters
  • x (Tensor) – The input tensor. Data type is ‘complex64’ or ‘complex128’.

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

Returns

Tensor, The output. Data type is ‘float32’ or ‘float64’, 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)
>>> z = paddle.as_real(y)
>>> print(z)
Tensor(shape=[2, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[0. , 1. ],
 [2. , 3. ],
 [4. , 5. ]],
[[6. , 7. ],
 [8. , 9. ],
 [10., 11.]]])