numpy.nanmax

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

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

Notes

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 the function is equivalent to np.max.

Examples

>>> a = np.array([[1, 2], [3, np.nan]])
>>> np.nanmax(a)
3.0
>>> 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])
2.0
>>> np.nanmax([1, 2, np.nan, np.inf])
inf

Previous topic

numpy.amax

Next topic

numpy.nanmin

This Page