pyinterp.dask.binning1d

Contents

pyinterp.dask.binning1d#

pyinterp.dask.binning1d(x, z, binning, weights=None)[source]#

Accumulate values into 1D bins from a dask array.

This function processes a dask array in parallel, binning values according to the x coordinates and accumulating statistics in each bin.

Parameters:
  • x (dask.array.Array) – Dask array of x coordinates.

  • z (dask.array.Array) – Dask array of values to bin.

  • binning (core.Binning1DHolder) – A Binning1D instance defining the bins. A copy is made internally, so the original is not modified.

  • weights (dask.array.Array | None) – Optional dask array of weights with the same shape as z.

Returns:

A new Binning1D instance with accumulated statistics.

Raises:
  • ImportError – If dask is not installed.

  • TypeError – If inputs are not dask arrays.

  • ValueError – If x and z have different shapes, or if weights shape doesn’t match.

Return type:

core.Binning1DHolder

Example

>>> import dask.array as da
>>> import numpy as np
>>> import pyinterp
>>> import pyinterp.dask as dask_stats

Create bins and data

>>> axis = pyinterp.Axis(np.linspace(0, 10, 11))
>>> binning = pyinterp.Binning1D(axis)

Create dask arrays

>>> x = da.random.uniform(0, 10, size=(10000,), chunks=1000)
>>> z = da.random.random((10000,), chunks=1000)

Compute binned statistics

>>> result = dask_stats.binning1d(x, z, binning)
>>> print(result.mean())