mean
result = mean(x, [on_invalid=])
Input: x, on_invalid · Output: result
What it is
Arithmetic mean of every element of x — a scalar, Vec, or Mat/Signal. A boolean mask counts as 0/1, so mean(x <= c) is the fraction of elements satisfying the condition (an empirical CDF at c). With no other argument, flattens x to one scalar Num (errors on an empty vector). On a Mat, the optional axis= keyword (0 or 1) computes the mean along just that dimension, returning a length-cols or length-rows Vec — see row_mean below for a dedicated column-Mat-returning version of the row case. on_invalid= ("propagate"/"ignore"/"error", see this section's intro) controls NaN/Inf handling; under "ignore" the divisor is the count of elements that survive filtering, not the original length.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = mean(x, [on_invalid=]) | x scalar, Vec, Mat, or SignalArithmetic mean of every element of x — a scalar, Vec, or Mat/Signal.on_invalid optionalon_invalid= ("propagate"/"ignore"/"error", see this section's intro) controls NaN/Inf handling. | result scalar, Num, or Vec | Returns a scalar Num with no axis=, or that Vec with one. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
readings = [2.1, 2.3, 2.2, 2.6, 2.4]
print("{len(readings)} readings, average {mean(readings):.2f}")
5 readings, average 2.32
from start-here
h = spectral_entropy(emg_signal, 256, 128)
print("mean spectral entropy: {mean(h)}")
from numerics-dsp
x = chisquare(4, 1000, seed=1)
print("sample mean: {mean(x)}") # converges to k=4, the distribution's own mean
sample mean: 4.108075
from numerics-dsp
runs = table("
channel, baseline, treated
1, 0.412, 0.240
2, 0.508, 0.301
3, 0.377, 0.219
")
print(runs)
print(mean(runs.baseline))
channel baseline treated
------- -------- -------
1 0.412 0.24
2 0.508 0.301
3 0.377 0.219
0.432333from collections-strings