reciprocal#

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

Return a new array with the reciprocal of each element in x.

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

  • 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 new array with the positive value of each element in x.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.reciprocal(x)
>>> print(y)
ivy.array([1.        , 0.5       , 0.33333333])
Array.reciprocal(self, /, *, out=None)[source]#

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

Parameters:
  • self (Array) – input array to compute the element-wise reciprocal for.

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

Return type:

Array

Returns:

ret – an array containing the element-wise reciprocal of self.

Examples

>>> x = ivy.array([1, 2, 3])
>>> y = x.reciprocal()
>>> print(y)
ivy.array([1., 0.5, 0.333])
Container.reciprocal(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

Parameters:
  • self (Container) – input container to compute the element-wise reciprocal for.

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

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

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

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

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

Return type:

Container

Returns:

ret – a container with the element-wise recirpocal of x

Examples

>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([4, 5]))
>>> y = x.reciprocal()
>>> print(y)
{
    a: ivy.array([1, 0.5]),
    b: ivy.array([0.25, 0.2])
}