![]() |
VOOZH | about |
numpy.maximum() is a NumPy function that compares two arrays (or scalars) element-wise and returns a new array containing the maximum value at each position. If any compared element is NaN, the NaN is returned. If both elements are NaN, the first NaN is returned.
Example: This example shows how numpy.maximum() compares two numbers and returns the larger one.
21
numpy.maximum(arr1, arr2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None)
Parameters:
Note: / -> Parameters before / are positional-only (must be passed without argument names).
* -> Parameters after * are keyword-only (must be passed using their names).
Example 1: This example compares two 1D arrays and returns the element-wise maximum values.
[ 3 8 125]
Explanation: np.maximum(a, b) compares each index, max(2, 3) -> 3, max(8, 3) -> 8 and max(125, 15) -> 125.
Example 2: This example shows how numpy.maximum() behaves when the arrays contain NaN values.
[nan nan nan]
Explanation:
Example 3: This example compares two arrays of different shapes using broadcasting and returns element-wise maxima.
[[3 4 7] [3 5 8]]
Explanation: