maximum#

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

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

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

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

  • use_where (bool, default: True) – Whether to use where() to calculate the maximum. If False, the maximum 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 be lower than the x2 values.

Examples

With ivy.Array inputs:

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

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.maximum(x, y)
>>> print(z)
{
    a: ivy.array([[1, 3],
                  [2, 4],
                  [3, 7]]),
    b: ivy.array([[1, 9],
                  [2, 9],
                  [3, 9]])
}

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.maximum(x, y)
>>> print(z)
{
    a: ivy.array([1, 5, 6]),
    b: ivy.array([5, 9, 7])
}
Array.maximum(self, x2, /, *, use_where=True, out=None)[source]#

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

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

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

  • use_where (bool, default: True) – Whether to use where() to calculate the maximum. If False, the maximum 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 be lower than the x2 values.

Examples

With ivy.Array inputs: >>> x = ivy.array([7, 9, 5]) >>> y = ivy.array([9, 3, 2]) >>> z = x.maximum(y) >>> print(z) ivy.array([9, 9, 5])

>>> x = ivy.array([1, 5, 9, 8, 3, 7])
>>> y = ivy.array([[9], [3], [2]])
>>> z = ivy.zeros((3, 6))
>>> x.maximum(y, out=z)
>>> print(z)
ivy.array([[9.,9.,9.,9.,9.,9.],
           [3.,5.,9.,8.,3.,7.],
           [2.,5.,9.,8.,3.,7.]])
>>> x = ivy.array([[7, 3]])
>>> y = ivy.array([0, 7])
>>> x.maximum(y, out=x)
>>> print(x)
ivy.array([[7, 7]])
Container.maximum(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.maximum. This method simply wraps the function, and so the docstring for ivy.maximum also applies to this method with minimal changes.

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

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

  • 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 maximum. If False, the maximum is calculated using the (x + y + |x - y|)/2 formula. Default is True.

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

Return type:

Container

Returns:

ret – An container with the elements of x1, but clipped to not be lower than the x2 values.

Examples

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 = x.maximum(y)
>>> print(z)
{
    a: ivy.array([[1, 3],
                  [2, 4],
                  [3, 7]]),
    b: ivy.array([[1, 9],
                  [2, 9],
                  [3, 9]])
}