complex#

ivy.complex(real, imag, *, out=None)[source]#

Returns a complex array formed by combining a real and an imaginary component element-wise. The real and imaginary components must have the same shape.

Parameters:
  • real (Union[Array, NativeArray]) – An array representing the real part of the complex numbers.

  • imag (Union[Array, NativeArray]) – An array representing the imaginary part of the complex numbers.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – A complex array where each element is formed by combining the corresponding elements of real and imag.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

>>> real = ivy.array([2.25, 3.25])
>>> imag = ivy.array([4.75, 5.75])
>>> x = ivy.complex(real, imag)
>>> print(x)
ivy.array([2.25+4.75j, 3.25+5.75j])
>>> real = ivy.array(1.)
>>> imag = ivy.array(2.)
>>> x = ivy.complex(real, imag)
>>> print(x)
ivy.array(1.+2.j)
>>> real = ivy.array([1., 2.])
>>> imag = ivy.array([3., 4.])
>>> x = ivy.complex(real, imag)
>>> print(x)
ivy.array([1.+3.j, 2.+4.j])