view_as_complex

paddle. view_as_complex ( input: Tensor ) Tensor [source]

Return a complex tensor that is a view of the input real 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 complex tensor is a view of the input real tensor, meaning that it shares the same memory with real tensor.

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

Illustration of as_complex
Parameters

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

Returns

Tensor, The output. Data type is ‘complex64’ or ‘complex128’, sharing the same memory with 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)]])