Skip to content

groupby_bins along two dims simultaneously #1056

Closed
@fmaussion

Description

@fmaussion

I probably missed it, but what is the way to apply groupby (or rather groupby_bins) in order to achieve the following in xarray?

da = xr.DataArray(np.arange(16).reshape((4, 4)))
da
<xarray.DataArray (dim_0: 4, dim_1: 4)>
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
Coordinates:
  * dim_0    (dim_0) int64 0 1 2 3
  * dim_1    (dim_1) int64 0 1 2 3

# should be aggregated to (in case of summing) to obtain
dagg
<xarray.DataArray (dim_0: 2, dim_1: 2)>
array([[10, 18],
       [42, 50]])
Coordinates:
  * dim_1    (dim_1) int64 0 2
  * dim_0    (dim_0) int64 0 2

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