numpy.nanmax(a, axis=None)

Return the maximum of an array or maximum along an axis ignoring any NaNs.

Parameters :

a : array_like

Array containing numbers whose maximum is desired. If a is not an array, a conversion is attempted.

axis : int, optional

Axis along which the maximum is computed. The default is to compute the maximum of the flattened array.

Returns :

nanmax : ndarray

An array with the same shape as a, with the specified axis removed. If a is a 0-d array, or if axis is None, a ndarray scalar is returned. The the same dtype as a is returned.

See also

Maximum across array including any Not a Numbers.
Minimum across array ignoring any Not a Numbers.
Shows which elements are Not a Number (NaN).
Shows which elements are not: Not a Number, positive and negative infinity


Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Positive infinity is treated as a very large number and negative infinity is treated as a very small (i.e. negative) number.

If the input has a integer type, an integer type is returned unless the input contains NaNs and infinity.


>>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nanmax(a)
>>> np.nanmax(a, axis=0)
array([ 3.,  2.])
>>> np.nanmax(a, axis=1)
array([ 2.,  3.])

When positive infinity and negative infinity are present:

>>> np.nanmax([1, 2, np.nan, np.NINF])
>>> np.nanmax([1, 2, np.nan, np.inf])

Previous topic


Next topic


This Page