NumPy | maximum method
maximum() method takes as input two arrays, and performs element-wise comparisons to return a new Numpy array containing the larger value of each pair.
The first input array.
The second input array.
If the shape of
x2 does not match, then the arrays must be able to broadcast to a common shape. Please see the examples below for clarification.
A Numpy array that holds the maximums of the pair-wise comparisons.
When the shape matches
x = np.array([2,3,7])y = np.array([1,5,6])z = np.maximum(x,y)zarray([2, 5, 7])
Here, we're doing three comparisons;
2 > 1,
3 < 5 and
7 > 6. The maximums are
When the shape does not match
We now examine the case where the shape of the two arrays does not match.
x = np.array([3,2])y = np.array([[1,4],[5,6]])z = np.maximum(x,y)zarray([[3, 4],[5, 6]])
Comparisons between NaNs
When comparison is performed between a number and
NaN is returned:
x = np.array([np.NaN,2])y = np.array([1,4])z = np.maximum(x,y)zarray([nan, 4.])