Reference · Vectors
vec.argmin
signature
vec.argmin(list | null) -> int | nullWhat it does
The position of the smallest number in a list, counting from 0. When several items tie,
the first one wins. The empty list has no smallest item and gives null.
Examples
print(vec.argmin([3, 1, 2]))let prices = [9.5, 7.25, 8]print(prices[vec.argmin(prices)])output
17.25Edge cases
- Ties go to the first:
vec.argmin([1, 1, 2])is0. - The empty list, or
null, givesnull. NaNis skipped; a list of onlyNaNgivesnull.- Ints and floats mix;
-infis the smallest of all.
print(vec.argmin([1, 1, 2]), vec.argmin([5]))print(vec.argmin([]), vec.argmin(null))print(vec.argmin([float("nan"), 2, 1]), vec.argmin([float("nan")]))print(vec.argmin([1, -math.inf, 2.5]))output
0 0null null2 null1Errors
An item that is not an int or a float, or an argument that is not a list, is a runtime error, not an error value.
this one fails
print(vec.argmin(["a", "b"]))output
line 1: `vec.argmin` expects a list of numbers, but item 0 is strChaining
The index picks the matching item out of another list, such as the name that goes with the lowest price:
let names = ["ann", "bob", "cy"]let prices = [9.5, 7.25, 8]print(names[vec.argmin(prices)])print(prices | vec.argmin)output
bob1See also
vec.argmax, vec.argsort, min, index_of
Thread
Thread 0 posts
On vec.argmin(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo