- scipy.stats.binned_statistic_dd(sample, values, statistic='mean', bins=10, range=None)¶
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.
sample : array_like
Data to histogram passed as a sequence of D arrays of length N, or as an (N,D) array.
values : array_like
The values on which the statistic will be computed. This must be the same shape as x.
statistic : string 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.
bins : sequence 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).
range : sequence, 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.
statistic : ndarray, shape(nx1, nx2, nx3,...)
The values of the selected statistic in each two-dimensional bin
edges : list of ndarrays
A list of D arrays describing the (nxi + 1) bin edges for each dimension
binnumber : 1-D ndarray of ints
This assigns to each observation an integer that represents the bin in which this observation falls. Array has the same length as values.
New in version 0.11.0.