numpy.maximum#

numpy.maximum(x1,x2,/,out=None,*,where=True,casting='same_kind',order='K',dtype=None,subok=True[,signature])=<ufunc'maximum'>#

Element-wise maximum of array elements.

Compare two arrays and return a new array containing the element-wisemaxima. If one of the elements being compared is a NaN, then thatelement is returned. If both elements are NaNs then the first isreturned. The latter distinction is important for complex NaNs, whichare defined as at least one of the real or imaginary parts being a NaN.The net effect is that NaNs are propagated.

Parameters:
x1, x2array_like

The arrays holding the elements to be compared.Ifx1.shape!=x2.shape, they must be broadcastable to a commonshape (which becomes the shape of the output).

outndarray, None, or tuple of ndarray and None, optional

A location into which the result is stored. If provided, it must havea shape that the inputs broadcast to. If not provided or None,a freshly-allocated array is returned. A tuple (possible only as akeyword argument) must have length equal to the number of outputs.

wherearray_like, optional

This condition is broadcast over the input. At locations where thecondition is True, theout array will be set to the ufunc result.Elsewhere, theout array will retain its original value.Note that if an uninitializedout array is created via the defaultout=None, locations within it where the condition is False willremain uninitialized.

**kwargs

For other keyword-only arguments, see theufunc docs.

Returns:
yndarray or scalar

The maximum ofx1 andx2, element-wise.This is a scalar if bothx1 andx2 are scalars.

See also

minimum

Element-wise minimum of two arrays, propagates NaNs.

fmax

Element-wise maximum of two arrays, ignores NaNs.

amax

The maximum value of an array along a given axis, propagates NaNs.

nanmax

The maximum value of an array along a given axis, ignores NaNs.

fmin,amin,nanmin

Notes

The maximum is equivalent tonp.where(x1>=x2,x1,x2) whenneither x1 nor x2 are nans, but it is faster and does properbroadcasting.

Examples

>>>importnumpyasnp>>>np.maximum([2,3,4],[1,5,2])array([2, 5, 4])
>>>np.maximum(np.eye(2),[0.5,2])# broadcastingarray([[ 1. ,  2. ],       [ 0.5,  2. ]])
>>>np.maximum([np.nan,0,np.nan],[0,np.nan,np.nan])array([nan, nan, nan])>>>np.maximum(np.inf,1)inf
On this page