median
result = median(x, [on_invalid=])
Input: x, on_invalid · Output: result
What it is
Middle order statistic of x (a scalar, Vec, or Mat/Signal, flattened): the middle element for an odd-length input, the average of the two middle elements when len(x) is even. on_invalid= ("propagate"/"ignore"/"error", see this section's intro) controls NaN/Inf handling. On a Mat, the optional axis= keyword (0 or 1) computes the median along just that dimension instead of flattening.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = median(x, [on_invalid=]) | x scalar, Vec, Mat, or SignalMiddle order statistic of x (a scalar, Vec, or Mat/Signal, flattened): the middle element for an odd-length input, the average of the two middle elements when len(x) is even.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 a length-cols/rows 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.
q1 = quantile(y, 0.25)
q3 = quantile(y, 0.75)
print("median = {median(y)}, IQR = {q3 - q1}")
median = 3.5, IQR = 6.75
from fundamentals
How it works
median(x) — the middle order statistic (average of the two middle elements for an even-length x, the standard convention).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.