xarray.DataArray.idxmin¶
-
DataArray.idxmin(dim=None, skipna=None, fill_value=<NA>, keep_attrs=None)¶ Return the coordinate label of the minimum value along a dimension.
Returns a new DataArray named after the dimension with the values of the coordinate labels along that dimension corresponding to minimum values along that dimension.
In comparison to
argmin(), this returns the coordinate label whileargmin()returns the index.- Parameters
dim (str, optional) – Dimension over which to apply idxmin. This is optional for 1D arrays, but required for arrays with 2 or more dimensions.
skipna (bool or None, default None) – If True, skip missing values (as marked by NaN). By default, only skips missing values for
float,complex, andobjectdtypes; other dtypes either do not have a sentinel missing value (int) orskipna=Truehas not been implemented (datetime64ortimedelta64).fill_value (Any, default NaN) – Value to be filled in case all of the values along a dimension are null. By default this is NaN. The fill value and result are automatically converted to a compatible dtype if possible. Ignored if
skipnais False.keep_attrs (bool, default False) – If True, the attributes (
attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.
- Returns
reduced – New DataArray object with idxmin applied to its data and the indicated dimension removed.
- Return type
Examples
>>> array = xr.DataArray( ... [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]} ... ) >>> array.min() <xarray.DataArray ()> array(-2) >>> array.argmin() <xarray.DataArray ()> array(4) >>> array.idxmin() <xarray.DataArray 'x' ()> array('e', dtype='<U1')
>>> array = xr.DataArray( ... [ ... [2.0, 1.0, 2.0, 0.0, -2.0], ... [-4.0, np.NaN, 2.0, np.NaN, -2.0], ... [np.NaN, np.NaN, 1.0, np.NaN, np.NaN], ... ], ... dims=["y", "x"], ... coords={"y": [-1, 0, 1], "x": np.arange(5.0) ** 2}, ... ) >>> array.min(dim="x") <xarray.DataArray (y: 3)> array([-2., -4., 1.]) Coordinates: * y (y) int64 -1 0 1 >>> array.argmin(dim="x") <xarray.DataArray (y: 3)> array([4, 0, 2]) Coordinates: * y (y) int64 -1 0 1 >>> array.idxmin(dim="x") <xarray.DataArray 'x' (y: 3)> array([16., 0., 4.]) Coordinates: * y (y) int64 -1 0 1