search
Search
Guest 0reps
Thanks for the thanks!
close
account_circle
Profile
exit_to_app
Sign out
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
A
A
brightness_medium
share
arrow_backShare Twitter Facebook

# NumPy | argmin method

Programming
chevron_right
Python
chevron_right
NumPy
chevron_right
Documentation
schedule Jul 1, 2022
Last updated
local_offer PythonNumPy
Tags

NumPy's `argmin(~)` method returns the index that corresponds to the smallest element in the array.

NOTE

If your array has missing values (i.e. `NaN`s), then the `np.argmin(~)` method will consider them as the smallest value. If you want to ignore missing values, then use the `np.nanargmin(~)` method instead.

# Parameters

1. `a` | `array_like`

The input array.

2. `axis` | `int` | `optional`

The axis along which to compute the method. For 2D arrays, if `axis=0`, then the method is performed column-wise, and if `axis=1` then row-wise. If no axis is provided, then NumPy will deem your array as a flattened array.

# Return value

If no `axis` is provided, then a scalar is returned. Otherwise, a NumPy array is returned.

# Examples

## One-dimensional arrays

``` x = np.array([3,5,2,1])np.argmin(x) 3 ```

Here, 3 is returned because the smallest value (i.e. 1) is located at index 3.

## Two-dimensional arrays

Suppose we have the following 2D NumPy array:

``` x = np.array([[5,4],[1,3]])x array([[5, 4], [1, 3]]) ```

### Max index of entire array

To obtain the index of the maximum value in the entire array, leave out the `axis` parameter:

``` np.argmin(x) 2 ```

### Max indices of every column

To obtain the index of the minimum values column-wise, set `axis=0`:

``` np.argmin(x, axis=0) array([1, 1]) ```

Here, we're going over each column of the matrix and computing the index of its smallest value.

### Max indices of every row

To obtain the index of the minimum values row-wise, set `axis=1`:

``` np.argmin(x, axis=1) array([1, 0]) ```

Here, we're going over each row of the matrix and computing the index of its smallest value.

mail