Statistics
Functions for computing histograms, correlation, convolution, covariance, and numerical integration.histogram
Compute the histogram of a dataset.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input data (flattened). |
bins | number | ArrayLike | 10 | If an integer, the number of equal-width bins. If an array, the bin edges (length nbins + 1). |
range | [number, number] | undefined | Lower and upper range of the bins. If undefined, uses [min(a), max(a)]. |
density | boolean | false | If true, the result is normalized so the integral over the range equals 1. |
weights | ArrayLike | undefined | Optional weights for each sample in a. |
[counts, bin_edges] where counts has shape [nbins] and bin_edges has shape [nbins + 1].
histogram2d
Compute the bi-dimensional histogram of two data samples.| Parameter | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Array of x-coordinates. |
y | ArrayLike | — | Array of y-coordinates (same length as x). |
bins | number | [number, number] | 10 | Number of bins for each dimension, or a pair [nx, ny]. |
range | [[number, number], [number, number]] | undefined | Range for each dimension: [[xmin, xmax], [ymin, ymax]]. |
density | boolean | false | If true, normalize the histogram. |
weights | ArrayLike | undefined | Optional weights for each paired sample. |
[H, xedges, yedges] where H has shape [nx, ny].
histogramdd
Compute the multidimensional histogram of some data.| Parameter | Type | Default | Description |
|---|---|---|---|
sample | ArrayLike | — | Data as an (N, D) array, where N is the number of samples and D is the number of dimensions. |
bins | number | number[] | 10 | Number of bins for each dimension. A single integer applies to all dimensions. |
range | [number, number][] | undefined | Range [min, max] for each dimension. |
density | boolean | false | If true, normalize the histogram. |
weights | ArrayLike | undefined | Optional weights for each sample. |
[H, edges] where H is the D-dimensional count array and edges is an array of D edge arrays.
histogram_bin_edges
Compute the bin edges for a histogram without computing the histogram itself. Useful for sharing bin edges across multiple histograms.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input data. |
bins | number | string | 10 | Number of bins, or a string naming a binning strategy (e.g., 'auto', 'sturges', 'sqrt'). |
range | [number, number] | undefined | Lower and upper range of the bins. |
weights | ArrayLike | undefined | Optional sample weights used for automatic bin edge selection. |
NDArray of bin edges with length nbins + 1.
bincount
Count occurrences of each value in an array of non-negative integers.| Parameter | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Array of non-negative integers. |
weights | ArrayLike | undefined | Weights for each value. If provided, the result is the sum of weights for each bin instead of counts. |
minlength | number | 0 | Minimum number of bins in the output. |
NDArray of length max(x) + 1 (or minlength, whichever is larger).
digitize
Return the indices of the bins to which each value belongs.| Parameter | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | Input array to be binned. |
bins | ArrayLike | — | Array of bin edges (must be monotonically increasing or decreasing). |
right | boolean | false | If false, the intervals are left-closed [a, b). If true, the intervals are right-closed (a, b]. |
NDArray of bin indices. An index i means bins[i-1] <= x < bins[i] (when right=false).
correlate
Cross-correlation of two 1-dimensional sequences.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | First input sequence. |
v | ArrayLike | — | Second input sequence. |
mode | 'valid' | 'same' | 'full' | 'valid' | 'valid': only where the sequences fully overlap. 'same': output length equals the longer input. 'full': full cross-correlation. |
NDArray containing the cross-correlation result.
convolve
Discrete, linear convolution of two 1-dimensional sequences.| Parameter | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | First input sequence. |
v | ArrayLike | — | Second input sequence. |
mode | 'valid' | 'same' | 'full' | 'full' | 'valid': only where the sequences fully overlap. 'same': output length equals the longer input. 'full': full convolution. |
NDArray containing the convolution result.
cov
Estimate a covariance matrix.| Parameter | Type | Default | Description |
|---|---|---|---|
m | ArrayLike | — | A 1-D or 2-D array of variables and observations. Each row represents a variable; each column an observation (when rowvar=true). |
y | ArrayLike | undefined | Additional set of variables and observations. Same form as m. |
rowvar | boolean | true | If true, each row is a variable. If false, each column is a variable. |
bias | boolean | false | If false, normalize by N - 1 (unbiased). If true, normalize by N. |
ddof | number | undefined | Override the default degrees of freedom. If provided, bias is ignored and the normalization factor is N - ddof. |
NDArray — the covariance matrix.
corrcoef
Return Pearson correlation coefficients.| Parameter | Type | Default | Description |
|---|---|---|---|
x | ArrayLike | — | A 1-D or 2-D array of variables and observations. |
y | ArrayLike | undefined | Additional set of variables and observations. |
rowvar | boolean | true | If true, each row is a variable. If false, each column is a variable. |
NDArray — the correlation coefficient matrix, with values in [-1, 1].
trapezoid
Integrate along the given axis using the composite trapezoidal rule.| Parameter | Type | Default | Description |
|---|---|---|---|
y | ArrayLike | — | Input array of values to integrate. |
x | ArrayLike | undefined | Sample points corresponding to y. If undefined, spacing is assumed uniform with interval dx. |
dx | number | 1 | Spacing between sample points when x is not provided. |
axis | number | undefined | Axis along which to integrate. |
number when integrating a 1-D array, NDArray when integrating along an axis of a multi-dimensional array.