real#

ivy.real(x, /, *, out=None)[source]#

Test each element x_i of the input array x to take only real part from it. Returns a float array, where it only contains . If element has complex type with zero complex part, the return value will be that element, else it only returns real part.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

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

Return type:

Array

Returns:

  • ret – an array containing test results. An element out_i is real number if x_i contain real number part only and if it is real number with complex part also then it returns the real number part. The returned array should have a data type of float.

  • The descriptions above assume an array input for simplicity, but

  • the method also accepts ivy.Container instances

  • in place of (class:ivy.Array or ivy.NativeArray)

  • instances, as shown in the type hints and also the examples below.

Examples

With ivy.Array inputs: >>> x = ivy.array([[[1.1], [2], [-6.3]]]) >>> z = ivy.real(x) >>> print(z) ivy.array([[[1.1], [2.], [-6.3]]])

>>> x = ivy.array([4.2-0j, 3j, 7+5j])
>>> z = ivy.real(x)
>>> print(z)
ivy.array([4.2, 0., 7.])

With ivy.Container input: >>> x = ivy.Container(a=ivy.array([-6.7-7j, 0.314+0.355j, 1.23]), b=ivy.array([5j, 5.32-6.55j, 3.001])) >>> z = ivy.real(x) >>> print(z) {

a: ivy.array([-6.7, 0.314, 1.23]), b: ivy.array([0., 5.32, 3.001])

}

Array.real(self, /, *, out=None)#

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

Parameters:
  • self (Array) – input array. Should have a real-valued floating-point data type.

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

Return type:

Array

Returns:

ret – an array containing test results. If input in an array is real then, it is returned unchanged. on the other hand, if it is complex then, it returns real part from it

Examples

>>> x = ivy.array([4+3j, 6+2j, 1-6j])
>>> x.real()
ivy.array([4., 6., 1.])
Container.real(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#

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

Parameters:
  • self (Container) – input container. Should have a real-valued floating-point data type.

  • key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key-chains to apply or not apply the method to. Default is None. (default: None)

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains (default: True) will be skipped. Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. (default: False) Default is False.

  • map_sequences (bool) – Whether to also map method to sequences (lists, tuples). (default: False) Default is False.

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

Return type:

Container

Returns:

ret – a container containing the test result. An element out_i is self_i if self_i is real number else took real number part only if self_i contains real number and complex number both. The returned array should have a data type of float.

Examples

>>> x = ivy.Container(a=ivy.array([-1j, 0.335+2.345j, 1.23+7j]),                          b=ivy.array([0.0, 1.2+3.3j, 1+0j]))
>>> x.real()
{
    a: ivy.array([0., 0.335, 1.23]),
    b: ivy.array([0.0, 1.2, 1.])
}