Descriptive statistics
Overview
Multik provides three core descriptive statistics functions through mk.stat:
Function | Description |
|---|---|
| Arithmetic mean of all elements, or along a given axis. |
| Median (middle value) of all elements. |
| Weighted average over all elements. |
mean
Returns the arithmetic mean of all elements in the array, or along a given axis.
Signatures
Dimension-specific overloads are also available:
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Input array. |
|
| Axis along which to compute mean. |
Returns: Double for the scalar form, or NDArray<Double, O> for the axis form.
Example
median
Returns the median of all elements in the array. Elements are sorted and the middle value is returned (or the average of the two middle values for even-length arrays).
Signature
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Input array. |
Returns: Double? — the median value, or null if the array is empty.
Example
average
Returns the weighted average of all elements. When no weights are provided, all elements are weighted equally (equivalent to mean).
Signature
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Input array. |
|
| Optional weights array (same shape as |
Returns: Double — the weighted average.
Example
Pitfalls
meanalways returnsDouble, even for integer arrays.medianreturnsDouble?— it can benullfor empty arrays.Axis-based
meanoverloads require explicit dimension type parameters, e.g.mk.stat.meanD2(a, axis = 0).The
weightsarray inaveragemust have the same shape as the input array.