TensorPlay
latest (dev)
Copy
View Markdown

Latest development documentation · Updated 2026-10-15

tensorplay.functional.view_as_complex

tensorplay.functional.view_as_complex(input) → Tensor[source]

Returns a view of input as a complex tensor. For an input complex tensor of size m1,m2,…,mi,2m1, m2, \dots, mi, 2, this function returns a new complex tensor of size m1,m2,…,mim1, m2, \dots, mi where the last dimension of the input tensor is expected to represent the real and imaginary components of complex numbers.

Warning

view_as_complex() is only supported for tensors with tensorplay.dtype tensorplay.float64 and tensorplay.float32. The input is expected to have the last dimension of size 2. In addition, the tensor must have a stride of 1 for its last dimension. The strides of all other dimensions must be even numbers.

Parameters:

input (Tensor) – the input tensor.

Example:

>>> x=tensorplay.randn(4, 2)
>>> x
tensor([[ 1.6116, -0.5772],
        [-1.4606, -0.9120],
        [ 0.0786, -1.7497],
        [-0.6561, -1.6623]])
>>> tensorplay.view_as_complex(x)
tensor([(1.6116-0.5772j), (-1.4606-0.9120j), (0.0786-1.7497j), (-0.6561-1.6623j)])

On this page

Ask DeepWiki