as_complex

paddle. as_complex ( x, name=None ) [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 arbitary shape), i.e. the size of the last axis shoule be 2, which represent the real and imag part of a complex number. The shape of the returned tensor is (*,).

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

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

Returns

The output. Data type is ‘complex64’ or ‘complex128’, with the same precision as the input.

Return type

Tensor

Examples

import paddle
x = paddle.arange(12, dtype=paddle.float32).reshape([2, 3, 2])
y = paddle.as_complex(x)
print(y.numpy())

# [[ 0. +1.j  2. +3.j  4. +5.j]
#  [ 6. +7.j  8. +9.j 10.+11.j]]