nanmax

array_api_extra.nanmax(a, /, *, axis=None, xp=None)

Return the maximum of the array elements along a given axis, ignoring NaNs.

Parameters:
  • a (Array) – Input array.

  • axis (int or tuple of ints or None, optional) – Axis or axes along which the maximum is computed. The default is to compute the maximum of the flattened array.

  • xp (array_namespace, optional) – The standard-compatible namespace for a. Default: infer.

Returns:

An array of maximum values along the given axis, ignoring NaNs.

Return type:

array

Examples

>>> import array_api_extra as xpx
>>> import array_api_strict as xp
>>> a = xp.asarray([[5, 3, xp.nan, 6], [4, xp.nan, 2, xp.nan]])
>>> xpx.nanmax(a)
Array(6., dtype=array_api_strict.float64)
>>> xpx.nanmax(a, axis=0)
Array([5., 3., 2., 6.], dtype=array_api_strict.float64)
>>> xpx.nanmax(a, axis=1)
Array([6., 4.], dtype=array_api_strict.float64)