Skip to content

Reimplement GroupBy.argmaxΒ #4476

Open
Open
@Hoeze

Description

@Hoeze

Please implement

Is your feature request related to a problem? Please describe.
Observed:

da.groupby("g").argmax(dim="t")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-84-15c199b0f7d4> in <module>
----> 1 da.groupby("g").argmax(dim="t")

AttributeError: 'DataArrayGroupBy' object has no attribute 'argmax'

Describe the solution you'd like
Expected: Vector of length len(unique(g)) containing the indices of da["t"] where the value was maximum.

Workaround:

da.groupby("g").apply(lambda c: c.argmax(dim="t"))
<xarray.DataArray 'da' (st: 11, g: 1)>
array([[ 7],
       [ 0],
       [14],
       [14],
       [ 0],
       [ 0],
       [ 7],
       [ 0],
       [14],
       [ 0],
       [ 7]])
Coordinates:
  * st      (st) object 'a' ... 'z'
  * g       (g) object 'E'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions