# 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('759a35c2-56db-4e02-945e-4eb95c57f71a','7ae4376f-537c-45ad-97f6-88980d856689','05891465-812d-4d46-a6d6-d40e3a97b6a6','../lite/tree/../notebooks/index.html?path=a842e0f3_ed69_45c3_87f9_6500c5154d9c.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="05891465-812d-4d46-a6d6-d40e3a97b6a6" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('759a35c2-56db-4e02-945e-4eb95c57f71a','05891465-812d-4d46-a6d6-d40e3a97b6a6')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('759a35c2-56db-4e02-945e-4eb95c57f71a','05891465-812d-4d46-a6d6-d40e3a97b6a6')">Open In Tab</button></div><div id="7ae4376f-537c-45ad-97f6-88980d856689" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
