# 11.6.3. astroML.stats.binned_statistic_dd¶

`astroML.stats.``binned_statistic_dd`(sample, values, statistic='mean', bins=10, range=None)[source]

Compute a multidimensional binned statistic for a set of data.

This is a generalization of a histogramdd function. A histogram divides the space into bins, and returns the count of the number of points in each bin. This function allows the computation of the sum, mean, median, or other statistic of the values within each bin.

Parameters
samplearray_like

Data to histogram passed as a sequence of D arrays of length N, or as an (N,D) array.

valuesarray_like

The values on which the statistic will be computed. This must be the same shape as x.

statisticstring or callable, optional

The statistic to compute (default is ‘mean’). The following statistics are available:

• ‘mean’ : compute the mean of values for points within each bin. Empty bins will be represented by NaN.

• ‘median’ : compute the median of values for points within each bin. Empty bins will be represented by NaN.

• ‘count’ : compute the count of points within each bin. This is identical to an unweighted histogram. values array is not referenced.

• ‘sum’ : compute the sum of values for points within each bin. This is identical to a weighted histogram.

• function : a user-defined function which takes a 1D array of values, and outputs a single numerical statistic. This function will be called on the values in each bin. Empty bins will be represented by function([]), or NaN if this returns an error.

binssequence or int, optional

The bin specification:

• A sequence of arrays describing the bin edges along each dimension.

• The number of bins for each dimension (nx, ny, … =bins)

• The number of bins for all dimensions (nx=ny=…=bins).

rangesequence, optional

A sequence of lower and upper bin edges to be used if the edges are not given explicitely in bins. Defaults to the minimum and maximum values along each dimension.

Returns
statisticndarray, shape(nx1, nx2, nx3,…)

The values of the selected statistic in each two-dimensional bin

edgeslist of ndarrays

A list of D arrays describing the (nxi + 1) bin edges for each dimension

`np.histogramdd`, `binned_statistic`, `binned_statistic_2d`