Return the coordinate label of the maximum value along a dimension. Returns a new `Dataset` 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:`~Data
(
self,
dim: Hashable | None = None,
*,
skipna: bool | None = None,
fill_value: Any = xrdtypes.NA,
keep_attrs: bool | None = None,
)
| 9294 | ) |
| 9295 | |
| 9296 | def idxmax( |
| 9297 | self, |
| 9298 | dim: Hashable | None = None, |
| 9299 | *, |
| 9300 | skipna: bool | None = None, |
| 9301 | fill_value: Any = xrdtypes.NA, |
| 9302 | keep_attrs: bool | None = None, |
| 9303 | ) -> Self: |
| 9304 | """Return the coordinate label of the maximum value along a dimension. |
| 9305 | |
| 9306 | Returns a new `Dataset` named after the dimension with the values of |
| 9307 | the coordinate labels along that dimension corresponding to maximum |
| 9308 | values along that dimension. |
| 9309 | |
| 9310 | In comparison to :py:meth:`~Dataset.argmax`, this returns the |
| 9311 | coordinate label while :py:meth:`~Dataset.argmax` returns the index. |
| 9312 | |
| 9313 | Parameters |
| 9314 | ---------- |
| 9315 | dim : str, optional |
| 9316 | Dimension over which to apply `idxmax`. This is optional for 1D |
| 9317 | variables, but required for variables with 2 or more dimensions. |
| 9318 | skipna : bool or None, optional |
| 9319 | If True, skip missing values (as marked by NaN). By default, only |
| 9320 | skips missing values for ``float``, ``complex``, and ``object`` |
| 9321 | dtypes; other dtypes either do not have a sentinel missing value |
| 9322 | (``int``) or ``skipna=True`` has not been implemented |
| 9323 | (``datetime64`` or ``timedelta64``). |
| 9324 | fill_value : Any, default: NaN |
| 9325 | Value to be filled in case all of the values along a dimension are |
| 9326 | null. By default this is NaN. The fill value and result are |
| 9327 | automatically converted to a compatible dtype if possible. |
| 9328 | Ignored if ``skipna`` is False. |
| 9329 | keep_attrs : bool or None, optional |
| 9330 | If True, the attributes (``attrs``) will be copied from the |
| 9331 | original object to the new one. If False, the new object |
| 9332 | will be returned without attributes. |
| 9333 | |
| 9334 | Returns |
| 9335 | ------- |
| 9336 | reduced : Dataset |
| 9337 | New `Dataset` object with `idxmax` applied to its data and the |
| 9338 | indicated dimension removed. |
| 9339 | |
| 9340 | See Also |
| 9341 | -------- |
| 9342 | DataArray.idxmax, Dataset.idxmin, Dataset.max, Dataset.argmax |
| 9343 | |
| 9344 | Examples |
| 9345 | -------- |
| 9346 | >>> array1 = xr.DataArray( |
| 9347 | ... [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]} |
| 9348 | ... ) |
| 9349 | >>> array2 = xr.DataArray( |
| 9350 | ... [ |
| 9351 | ... [2.0, 1.0, 2.0, 0.0, -2.0], |
| 9352 | ... [-4.0, np.nan, 2.0, np.nan, -2.0], |
| 9353 | ... [np.nan, np.nan, 1.0, np.nan, np.nan], |