MCPcopy
hub / github.com/pydata/xarray / idxmax

Method idxmax

xarray/core/dataarray.py:6106–6201  ·  view source on GitHub ↗

Return the coordinate label of the maximum value along a dimension. Returns a new `DataArray` named after the dimension with the values of the coordinate labels along that dimension corresponding to maximum values along that dimension. In comparison to :py:meth:`~Da

(
        self,
        dim: Hashable = None,
        *,
        skipna: bool | None = None,
        fill_value: Any = dtypes.NA,
        keep_attrs: bool | None = None,
    )

Source from the content-addressed store, hash-verified

6104 )
6105
6106 def idxmax(
6107 self,
6108 dim: Hashable = None,
6109 *,
6110 skipna: bool | None = None,
6111 fill_value: Any = dtypes.NA,
6112 keep_attrs: bool | None = None,
6113 ) -> Self:
6114 """Return the coordinate label of the maximum value along a dimension.
6115
6116 Returns a new `DataArray` named after the dimension with the values of
6117 the coordinate labels along that dimension corresponding to maximum
6118 values along that dimension.
6119
6120 In comparison to :py:meth:`~DataArray.argmax`, this returns the
6121 coordinate label while :py:meth:`~DataArray.argmax` returns the index.
6122
6123 Parameters
6124 ----------
6125 dim : Hashable, optional
6126 Dimension over which to apply `idxmax`. This is optional for 1D
6127 arrays, but required for arrays with 2 or more dimensions.
6128 skipna : bool or None, default: None
6129 If True, skip missing values (as marked by NaN). By default, only
6130 skips missing values for ``float``, ``complex``, and ``object``
6131 dtypes; other dtypes either do not have a sentinel missing value
6132 (``int``) or ``skipna=True`` has not been implemented
6133 (``datetime64`` or ``timedelta64``).
6134 fill_value : Any, default: NaN
6135 Value to be filled in case all of the values along a dimension are
6136 null. By default this is NaN. The fill value and result are
6137 automatically converted to a compatible dtype if possible.
6138 Ignored if ``skipna`` is False.
6139 keep_attrs : bool or None, optional
6140 If True, the attributes (``attrs``) will be copied from the
6141 original object to the new one. If False, the new object
6142 will be returned without attributes.
6143
6144 Returns
6145 -------
6146 reduced : DataArray
6147 New `DataArray` object with `idxmax` applied to its data and the
6148 indicated dimension removed.
6149
6150 See Also
6151 --------
6152 Dataset.idxmax, DataArray.idxmin, DataArray.max, DataArray.argmax
6153
6154 Examples
6155 --------
6156 >>> array = xr.DataArray(
6157 ... [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]}
6158 ... )
6159 >>> array.max()
6160 <xarray.DataArray ()> Size: 8B
6161 array(2)
6162 >>> array.argmax(...)
6163 {'x': <xarray.DataArray ()> Size: 8B

Callers

nothing calls this directly

Calls 1

argmaxMethod · 0.45

Tested by

no test coverage detected