pyinterp.DescriptiveStatistics#
- pyinterp.DescriptiveStatistics(values: object, weights: object | None = None, axis: collections.abc.Sequence[int] | None = None, dtype: object | None = None) object#
Univariate descriptive statistics.
Computes statistics using numerically stable algorithms that support parallel and online computation with arbitrary weights.
Reference: https://doi.org/10.1007/s00180-015-0637-z
- Parameters:
values – Input array of values.
weights – Optional array of weights (same shape as values).
axis – Optional axis or axes along which to compute statistics.
dtype – Data type for internal storage, either ‘float32’ or ‘float64’. Determines precision and memory usage. Defaults to ‘float64’.
Examples
>>> import numpy as np >>> import pyinterp
Compute statistics for a 1D array with float64 (default)
>>> data = np.random.randn(100) >>> stats = pyinterp.DescriptiveStatistics(data) >>> print(f"Mean: {stats.mean()}, Std: {np.sqrt(stats.variance())}")
Compute statistics with float32 for reduced memory usage
>>> data = data.astype('float32') >>> stats = pyinterp.DescriptiveStatistics(data, dtype='float32')
Compute along a specific axis
>>> data = np.random.randn(100, 50) >>> stats_axis = pyinterp.DescriptiveStatistics(data, axis=[0]) >>> print(f"Means shape: {stats_axis.mean().shape}")
Compute with weights
>>> weights = np.random.rand(100, 50) >>> stats_weighted = pyinterp.DescriptiveStatistics(data, weights=weights)