ivy.imag(val, /, *, out=None)[source]#

Return the imaginary part of a complex number for each element x_i of the input array val.

  • val (Union[Array, NativeArray]) – input array. Should have a complex floating-point data type.

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:



  • ret – Returns an array with the imaginary part of complex numbers. The returned arrau must have a floating-point data type determined by the precision of val (e.g., if val is complex64, the returned array must be float32).

  • This method conforms to the

  • Array API Standard.

  • This docstring is an extension of the

  • `docstring <https (//

  • API_specification/generated/array_api.imag.html>`_

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


>>> b = ivy.array(np.array([1+2j, 3+4j, 5+6j]))
>>> b
ivy.array([1.+2.j, 3.+4.j, 5.+6.j])
>>> ivy.imag(b)
ivy.array([2., 4., 6.])

Imaginary part of the array.


ret – array containing the imaginary part of each element in the array. The returned array must have the same shape and data type as the original array.

Container.imag(self, /, *, out=None)[source]#

ivy.Container instance method variant of ivy.imag. This method simply wraps the function, and so the docstring for ivy.imag also applies to this method with minimal changes.

  • val – Array-like input.

  • out (Optional[Container], default: None) – optional output array, for writing the result to.

Return type:



ret – Returns an Container including arrays with the imaginary part of complex numbers.


>>> x = ivy.Container(a=ivy.array(np.array([1+2j, 3+4j, 5+6j])),
                        b=ivy.array(np.array([-2.25 + 4.75j, 3.25 + 5.75j])))
>>> x
    a: ivy.array([1.+2.j, 3.+4.j, 5.+6.j]),
    b: ivy.array([-2.25+4.75j, 3.25+5.75j])
>>> x.imag()
    a: ivy.array([2., 4., 6.]),
    b: ivy.array([4.75, 5.75])