max

max(x: array, /, *, axis: int | Tuple[int, ...] | None = None, keepdims: bool = False) array

Calculates the maximum value of the input array x.

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

  • axis (Optional[Union[int, Tuple[int, ...]]]) – 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) – 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). Otherwise, if False, the reduced axes (dimensions) must not be included in the result. Default: False.

Returns:

out (array) – 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.

Notes

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

The order of signed zeros is unspecified and thus implementation-defined. When choosing between -0 or +0 as a maximum value, specification-compliant libraries may choose to return either value.

For backward compatibility, conforming implementations may support complex numbers; however, inequality comparison of complex numbers is unspecified and thus implementation-defined (see Complex Number Ordering).

Special Cases

For floating-point operands,

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

Changed in version 2023.12: Clarified that the order of signed zeros is implementation-defined.