# xarray.DataArray.argmax

#### DataArray.argmax(dim=None, , axis=None, keep_attrs=None, skipna=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L6557-L6656)

Index or indices of the maximum of the DataArray over one or more dimensions.

If a sequence is passed to ‘dim’, then result returned as dict of DataArrays,
which can be passed directly to isel(). If a single str is passed to ‘dim’ then
returns a DataArray with dtype int.

If there are multiple maxima, the indices of the first one found will be
returned.

* **Parameters:**
  * **dim** (`"..."`, [`str`](xarray.DataArray.str.html.md#xarray.DataArray.str), `Iterable` of `Hashable` or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – The dimensions over which to find the maximum. By default, finds maximum over
    all dimensions - for now returning an int for backward compatibility, but
    this is deprecated, in future will return a dict with indices for all
    dimensions; to return a dict with all dimensions now, pass ‘…’.
  * **axis** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – Axis over which to apply argmax. Only one of the ‘dim’ and ‘axis’ arguments
    can be supplied.
  * **keep_attrs** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, the attributes (attrs) will be copied from the original
    object to the new one. If False, the new object will be
    returned without attributes.
  * **skipna** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, skip missing values (as marked by NaN). By default, only
    skips missing values for float dtypes; other dtypes either do not
    have a sentinel missing value (int) or skipna=True has not been
    implemented (object, datetime64 or timedelta64).
* **Returns:**
  **result** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray) or [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict) of [`DataArray`](xarray.DataArray.html.md#xarray.DataArray))

#### SEE ALSO
[`Variable.argmax`](xarray.Variable.argmax.html.md#xarray.Variable.argmax), [`DataArray.idxmax`](xarray.DataArray.idxmax.html.md#xarray.DataArray.idxmax)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('caf9b352-8aa2-485e-a319-4f8916fa74d0','38e4067a-518b-4c45-9759-5b3bfc96b98a','a2a51e81-9c1f-418f-88ba-c0802c980bcb','../lite/tree/../notebooks/index.html?path=d15c167a_de7c_43dc_991f_88841110598c.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> array = xr.DataArray([0, 2, -1, 3], dims="x")
>>> array.max()
<xarray.DataArray ()> Size: 8B
array(3)
>>> array.argmax(...)
{'x': <xarray.DataArray ()> Size: 8B
array(3)}
>>> array.isel(array.argmax(...))
<xarray.DataArray ()> Size: 8B
array(3)
```

```pycon
>>> array = xr.DataArray(
...     [[[3, 2, 1], [3, 1, 2], [2, 1, 3]], [[1, 3, 2], [2, 5, 1], [2, 3, 1]]],
...     dims=("x", "y", "z"),
... )
>>> array.max(dim="x")
<xarray.DataArray (y: 3, z: 3)> Size: 72B
array([[3, 3, 2],
       [3, 5, 2],
       [2, 3, 3]])
Dimensions without coordinates: y, z
>>> array.argmax(dim="x")
<xarray.DataArray (y: 3, z: 3)> Size: 72B
array([[0, 1, 1],
       [0, 1, 0],
       [0, 1, 0]])
Dimensions without coordinates: y, z
>>> array.argmax(dim=["x"])
{'x': <xarray.DataArray (y: 3, z: 3)> Size: 72B
array([[0, 1, 1],
       [0, 1, 0],
       [0, 1, 0]])
Dimensions without coordinates: y, z}
>>> array.max(dim=("x", "z"))
<xarray.DataArray (y: 3)> Size: 24B
array([3, 5, 3])
Dimensions without coordinates: y
>>> array.argmax(dim=["x", "z"])
{'x': <xarray.DataArray (y: 3)> Size: 24B
array([0, 1, 0])
Dimensions without coordinates: y, 'z': <xarray.DataArray (y: 3)> Size: 24B
array([0, 1, 2])
Dimensions without coordinates: y}
>>> array.isel(array.argmax(dim=["x", "z"]))
<xarray.DataArray (y: 3)> Size: 24B
array([3, 5, 3])
Dimensions without coordinates: y
```

<div id="a2a51e81-9c1f-418f-88ba-c0802c980bcb" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('caf9b352-8aa2-485e-a319-4f8916fa74d0','a2a51e81-9c1f-418f-88ba-c0802c980bcb')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('caf9b352-8aa2-485e-a319-4f8916fa74d0','a2a51e81-9c1f-418f-88ba-c0802c980bcb')">Open In Tab</button></div><div id="38e4067a-518b-4c45-9759-5b3bfc96b98a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
