numpy.maximum

numpy.maximum(x1, x2[, out])

Element-wise maximum of array elements.

Compare two arrays and returns a new array containing the element-wise maxima.

Parameters:

x1, x2 : array_like

The arrays holding the elements to be compared.

Returns:

y : {ndarray, scalar}

The maximum of x1 and x2, element-wise. Returns scalar if both x1 and x2 are scalars.

See also

minimum
element-wise minimum

Notes

Equivalent to np.where(x1 > x2, x1, x2) but faster and does proper broadcasting.

Examples

>>> np.maximum([2, 3, 4], [1, 5, 2])
array([2, 5, 4])
>>> np.maximum(np.eye(2), [0.5, 2])
array([[ 1. ,  2. ],
       [ 0.5,  2. ]])

Previous topic

numpy.sign

Next topic

numpy.minimum

This Page

Quick search