amax#

ivy.amax(x, /, *, axis=None, keepdims=False, out=None)[source]#

Calculate the maximum value of the input array x.

Note

amax is an alias of max and both function behaves similarly in every backend except PyTorch and PaddlePaddle (see PyTorch’s amax function documentation<https://pytorch.org/docs/stable/generated/torch.amax.html>`_) (see PaddlePaddle’s amax function documentation<https://www.paddlepaddle.org.cn/ documentation/docs/zh/api/paddle/amax_cn.html>`_)

Note

When the number of elements over which to compute the maximum value is zero, the maximum value is implementation-defined. Specification-compliant libraries may choose to raise an error, return a sentinel value (e.g., if x is a floating-point input array, return NaN), or return the minimum possible value for the input array x data type (e.g., if x is a floating-point array, return -infinity).

Special Cases

For floating-point operands,

  • If x_i is NaN, the maximum value is NaN (i.e., NaN values propagate).

Parameters:
  • x (Union[Array, NativeArray]) – input array. Should have a real-valued data type.

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which maximum values must be computed. By default, the maximum value must be computed over the entire array. If a tuple of integers, maximum values must be computed over multiple axes. Default: None.

  • keepdims (bool, default: False) – optional boolean, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see `broadcasting<https://data-apis.org/ array-api/latest/API_specification/broadcasting.html#broadcasting>`_). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

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

Return type:

Array

Returns:

ret – if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value; otherwise, a non-zero-dimensional array containing the maximum values. The returned array must have the same data type as x.

This function conforms to the Array API Standard. This docstring is an extension of the docstring 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.

Examples

With ivy.Array input:

>>> x = ivy.array([1, 2, 3])
>>> y = ivy.amax(x)
>>> print(y)
ivy.array(3)
>>> x = ivy.array([0, 1, 2])
>>> z = ivy.array([0, 0, 0])
>>> y = ivy.amax(x, out=z)
>>> print(z)
ivy.array(2)
>>> x = ivy.array([[0, 1, 2], [4, 6, 10]])
>>> y = ivy.amax(x, axis=0, keepdims=True)
>>> print(y)
ivy.array([[4, 6, 10]])
>>> x = ivy.native_array([[0, 1, 2], [4, 6, 10]])
>>> y = ivy.amax(x)
>>> print(y)
ivy.array(10)

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4]))
>>> y = ivy.amax(x)
>>> print(y)
{
    a: ivy.array(3),
    b: ivy.array(4)
}
Array.amax(self, /, *, axis=None, keepdims=False, out=None)[source]#

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

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

  • axis (Optional[Union[int, Sequence[int]]], default: None) – axis or axes along which maximum values must be computed. By default, the maximum value must be computed over the entire array. If a tuple of integers, maximum values must be computed over multiple axes. Default: None.

  • keepdims (bool, default: False) – optional boolean, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see `broadcasting<https://data-apis.org/array-api/latest/ API_specification/broadcasting.html#broadcasting>`_). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

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

Return type:

Array

Returns:

ret – if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value; otherwise, a non-zero-dimensional array containing the maximum values. The returned array must have the same data type as x.

Examples

>>> x = ivy.array([3., 4., 5.])
>>> y = x.amax()
>>> print(y)
ivy.array(5.)
>>> x = ivy.array([[-1, 0, 1], [2, 3, 4]])
>>> y = x.amax(axis=1)
>>> print(y)
ivy.array([1,  4])
>>> x = ivy.array([0.1, 1.1, 2.1])
>>> y = ivy.array(0.)
>>> x.amax(out=y)
>>> print(y)
ivy.array(2.1)
Container.amax(self, /, *, axis=None, keepdims=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

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

  • axis (Optional[Union[int, Sequence[int], Container]], default: None) – axis or axes along which maximum values must be computed. By default, the maximum value must be computed over the entire array. If a tuple of integers, maximum values must be computed over multiple axes. Default: None.

  • keepdims (Union[bool, Container], default: False) – optional boolean, if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see `broadcasting<https://data-apis.org/array-api/ latest/API_specification/ broadcasting.html#broadcasting>`_). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

  • 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, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – container, if the maximum value was computed over the entire array, a zero-dimensional array containing the maximum value; otherwise, a non-zero-dimensional array containing the maximum values. The returned array must have the same data type as x.

Examples

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([1, 2, 3]),
...                   b=ivy.array([2, 3, 4]))
>>> y = x.amax()
>>> print(y)
{
    a: ivy.array(3),
    b: ivy.array(4)
}
>>> x = ivy.Container(a=ivy.array([[1, 2, 3], [-1, 0, 2]]),
...                   b=ivy.array([[2, 3, 4], [0, 1, 2]]))
>>> y = x.amax(axis=1)
>>> print(y)
{
    a:ivy.array([3, 2]),
    b:ivy.array([4, 2])
}