minimum#

ivy.minimum(x1, x2, /, *, use_where=True, out=None)[source]#

Return the min of x1 and x2 (i.e. x1 < x2 ? x1 : x2) element-wise.

Parameters:
  • x1 (Union[Array, NativeArray]) – Input array containing elements to minimum threshold.

  • x2 (Union[Array, NativeArray]) – Tensor containing minimum values, must be broadcastable to x1.

  • use_where (bool, default: True) – Whether to use where() to calculate the minimum. If False, the minimum is calculated using the (x + y - |x - y|)/2 formula. Default is True.

  • 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 – An array with the elements of x1, but clipped to not exceed the x2 values.

Examples

With ivy.Array inputs:

>>> x = ivy.array([7, 9, 5])
>>> y = ivy.array([9, 3, 2])
>>> z = ivy.minimum(x, y)
>>> print(z)
ivy.array([7, 3, 2])
>>> x = ivy.array([1, 5, 9, 8, 3, 7])
>>> y = ivy.array([[9], [3], [2]])
>>> z = ivy.zeros((3, 6), dtype=ivy.int32)
>>> ivy.minimum(x, y, out=z)
>>> print(z)
ivy.array([[1, 5, 9, 8, 3, 7],
           [1, 3, 3, 3, 3, 3],
           [1, 2, 2, 2, 2, 2]])
>>> x = ivy.array([[7, 3]])
>>> y = ivy.array([0, 7])
>>> ivy.minimum(x, y, out=x)
>>> print(x)
ivy.array([[0, 3]])

With one ivy.Container input:

>>> x = ivy.array([[1, 3], [2, 4], [3, 7]])
>>> y = ivy.Container(a=ivy.array([1, 0,]),b=ivy.array([-5, 9]))
>>> z = ivy.minimum(x, y)
>>> print(z)
{
    a: ivy.array([[1, 0],
                  [1, 0],
                  [1, 0]]),
    b: ivy.array([[-5, 3],
                  [-5, 4],
                  [-5, 7]])
}

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([1, 3, 1]),
...                   b=ivy.array([2, 8, 5]))
>>> y = ivy.Container(a=ivy.array([1, 5, 6]),
...                   b=ivy.array([5, 9, 7]))
>>> z = ivy.minimum(x, y)
>>> print(z)
{
    a: ivy.array([1, 3, 1]),
    b: ivy.array([2, 8, 5])
}
Array.minimum(self, x2, /, *, use_where=True, out=None)[source]#

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

Parameters:
  • self (Array) – Input array containing elements to minimum threshold.

  • x2 (Union[Array, NativeArray]) – Tensor containing minimum values, must be broadcastable to x1.

  • use_where (bool, default: True) – Whether to use where() to calculate the minimum. If False, the minimum is calculated using the (x + y - |x - y|)/2 formula. Default is True.

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

Returns:

ret – An array with the elements of x1, but clipped to not exceed the x2 values.

Examples

With ivy.Array inputs:

>>> x = ivy.array([7, 9, 5])
>>> y = ivy.array([9, 3, 2])
>>> z = x.minimum(y)
>>> print(z)
ivy.array([7, 3, 2])
>>> x = ivy.array([1, 5, 9, 8, 3, 7])
>>> y = ivy.array([[9], [3], [2]])
>>> z = ivy.zeros((3, 6))
>>> x.minimum(y, out=z)
>>> print(z)
ivy.array([[1.,5.,9.,8.,3.,7.],
           [1.,3.,3.,3.,3.,3.],
           [1.,2.,2.,2.,2.,2.]])
>>> x = ivy.array([[7, 3]])
>>> y = ivy.array([0, 7])
>>> x.minimum(y, out=x)
>>> print(x)
ivy.array([[0, 3]])
Container.minimum(self, x2, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, use_where=True, out=None)[source]#

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

Parameters:
  • self (Union[Container, Array, NativeArray]) – Input array containing elements to minimum threshold.

  • x2 (Union[Container, Array, NativeArray]) – The other container or number to compute the minimum against.

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

  • use_where (Union[bool, Container], default: True) – Whether to use where() to calculate the minimum. If False, the minimum is calculated using the (x + y - |x - y|)/2 formula. Default is True.

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

Container object with all sub-arrays having the minimum values computed.

Examples

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([1, 3, 1]),
...                   b=ivy.array([2, 8, 5]))
>>> y = ivy.Container(a=ivy.array([1, 5, 6]),
...                   b=ivy.array([5, 9, 7]))
>>> z = x.minimum(y)
>>> print(z)
{
    a: ivy.array([1, 3, 1]),
    b: ivy.array([2, 8, 5])
}