search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# NumPy | maximum method

schedule Aug 12, 2023
Last updated
local_offer
PythonNumPy
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Numpy's `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.

# Parameters

1. `x1` | `array-like`

The first input array.

2. `x2` | `array-like`

The second input array.

If the shape of `x1` and `x2` does not match, then the arrays must be able to broadcast to a common shape. Please see the examples below for clarification.

# Return value

A Numpy array that holds the maximums of the pair-wise comparisons.

# Examples

## When the shape matches

``` x = np.array([2,3,7])y = np.array([1,5,6])z = np.maximum(x,y)z array([2, 5, 7]) ```

Here, we're doing three comparisons; `2 > 1`, `3 < 5` and `7 > 6`. The maximums are `2`, `5` and `7`.

## 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)z array([[3, 4], [5, 6]]) ```

## Comparisons between NaNs

When comparison is performed between a number and `NaN`, then `NaN` is returned:

``` x = np.array([np.NaN,2])y = np.array([1,4])z = np.maximum(x,y)z array([nan, 4.]) ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!