argquantile
result = argquantile(x, q)
Input: x, q · Output: result
What it is
Index into x (a Vec or flattened Mat/Signal) nearest the q-quantile rank, computed as round(q*(n-1)) where n = len(x); q is a scalar in [0, 1]. Unlike quantile, which may interpolate between two elements, this always lands on a real element of x.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = argquantile(x, q) | x Vec, Mat, or SignalIndex into x (a Vec or flattened Mat/Signal) nearest the q-quantile rank, computed as round(q*(n-1)) where n = len(x).q scalarq is a scalar in [0, 1]. | result scalar or Num | Returns a scalar Num index (0-based). |
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
argquantile(x, q) — the index (into x) of the element at the nearest-rank quantile position (round(q*(n-1))) — unlike quantile itself, this must land on an actual element, so it can't interpolate between two.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.