> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Flox

> Flox: Strategies for fast GroupBy reductions with dask.array. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/data_processing/flox/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/data_processing/flox/flox.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/data_processing/flox.ipynb)

Description:
- Strategies for fast GroupBy reductions with dask.array

Resources:
- [GitHub] https://github.com/xarray-contrib/flox
- [Docs] https://flox.readthedocs.io/en/latest/
- [Pangeo Showcase talk] https://discourse.pangeo.io/t/november-17-2021-flox-fast-furious-groupby-reductions-with-dask-at-pangeo-scale/2016

## Example 1

GroupBy single variable with numpy and xarray

```python
import numpy as np
import xarray as xr

from flox.xarray import xarray_reduce

labels = xr.DataArray(
    [1, 2, 3, 1, 2, 3, 0, 0, 0],
    dims="x",
    name="label",
)

da = xr.DataArray(
    np.ones((9,)), dims="x", name="array"
)

xarray_reduce(da, labels, func="sum")
```

## Example 2

GroupBy with Dask and Xarray

```python
import xarray as xr
from flox.xarray import xarray_reduce

da = xr.DataArray(
    np.ones((9,)), dims="x", name="array"
)
da_chunked = da.chunk(x=2)

labels = xr.DataArray(
    [1, 2, 3, 1, 2, 3, 0, 0, 0],
    dims="x",
    name="label",
)
labels_chunked = labels.chunk(x=3)

xarray_reduce(da_chunked, labels, func="sum")
```
