numpy.nanmax#
- numpy.nanmax(a,axis=None,out=None,keepdims=<novalue>,initial=<novalue>,where=<novalue>)[source]#
Return the maximum of an array or maximum along an axis, ignoring anyNaNs. When all-NaN slices are encountered a
RuntimeWarningisraised and NaN is returned for that slice.- Parameters:
- aarray_like
Array containing numbers whose maximum is desired. Ifa is not anarray, a conversion is attempted.
- axis{int, tuple of int, None}, optional
Axis or axes along which the maximum is computed. The default is to computethe maximum of the flattened array.
- outndarray, optional
Alternate output array in which to place the result. The defaultis
None; if provided, it must have the same shape as theexpected output, but the type will be cast if necessary. SeeOutput type determination for more details.- keepdimsbool, optional
If this is set to True, the axes which are reduced are leftin the result as dimensions with size one. With this option,the result will broadcast correctly against the originala.If the value is anything but the default, thenkeepdims will be passed through to the
maxmethodof sub-classes ofndarray. If the sub-classes methodsdoes not implementkeepdims any exceptions will be raised.- initialscalar, optional
The minimum value of an output element. Must be present to allowcomputation on empty slice. See
reducefor details.New in version 1.22.0.
- wherearray_like of bool, optional
Elements to compare for the maximum. See
reducefor details.New in version 1.22.0.
- Returns:
- nanmaxndarray
An array with the same shape asa, with the specified axis removed.Ifa is a 0-d array, or if axis is None, an ndarray scalar isreturned. The same dtype asa is returned.
See also
nanminThe minimum value of an array along a given axis, ignoring any NaNs.
amaxThe maximum value of an array along a given axis, propagating any NaNs.
fmaxElement-wise maximum of two arrays, ignoring any NaNs.
maximumElement-wise maximum of two arrays, propagating any NaNs.
isnanShows which elements are Not a Number (NaN).
isfiniteShows which elements are neither NaN nor infinity.
amin,fmin,minimum
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 negativeinfinity 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
>>>importnumpyasnp>>>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.inf])2.0>>>np.nanmax([1,2,np.nan,np.inf])inf