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 (*,).

  • 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.


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


>>> 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)]])