var
result = var(x, [on_invalid=])
Input: x, on_invalid · Output: result
What it is
Sample variance, same N-1 (unbiased) denominator as std, so var(x) == std(x)^2 always holds. x is a scalar, Vec, or Mat/Signal, flattened. On a Mat, the optional axis= keyword (0 or 1) computes the variance down each column or across each row instead, returning a length-cols/rows Vec (same support as std). on_invalid= ("propagate"/"ignore"/"error", see this section's intro) controls NaN/Inf handling.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = var(x, [on_invalid=]) | x scalar, Vec, Mat, or Signalx is a scalar, Vec, or Mat/Signal, flattened.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.
v = [5.0, 3.0, 8.0, 1.0, 9.0]
print("prod={prod(v)}")
print("argmedian={argmedian(v)} argquantile(0.9)={argquantile(v, 0.9)} argmean={argmean(v)}")
print("clamp={clamp([-5, 0, 5, 10], 0, 5)}")
print("var={var(v)} std^2={std(v)^2}")
print("lse={lse(v)}")
prod=1080 argmedian=0 argquantile(0.9)=4 argmean=0 clamp=[0, 0, 5, 5] var=11.2 std^2=11.2 lse=9.328591
from core-math
How it works
var(x) — sample variance, same N-1 (unbiased) denominator as std, so var(x) == std(x)^2 always holds.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.