megengine.functional.complex

complex(real, imag)[source]

Constructs a complex tensor with its real part equal to real and its imaginary part equal to imag.

Parameters
  • real (Tensor) – the real part of the complex tensor. Must be float.

  • imag (Tensor) – the imaginary part of the complex tensor. Must be float.

Return type

Tensor

Returns

the complex tensor

Examples

>>> real = Tensor([1, 2], dtype=np.float32)
>>> imag = Tensor([3, 4], dtype=np.float32)
>>> z = F.complex(real, imag)
>>> z
Tensor([1.+3.j 2.+4.j], dtype=complex64, device=xpux:0)
>>> z.dtype
dtype('complex64')