max

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

Calculates the maximum value of the input array x.

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 (array) – input array. Should have a numeric 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.