Reference · Vectors
vec.argmax
signature
vec.argmax(list | null) -> int | nullWhat it does
The position of the largest number in a list, counting from 0. When several items tie,
the first one wins. The empty list has no largest item and gives null.
Examples
print(vec.argmax([3, 1, 2]))let scores = [71, 88.5, 88.5]print(vec.argmax(scores), scores[vec.argmax(scores)])output
01 88.5Edge cases
- Ties go to the first:
vec.argmax([2, 2, 1])is0. - The empty list, or
null, givesnull. NaNis skipped; a list of onlyNaNgivesnull.infis the largest of all.
print(vec.argmax([2, 2, 1]), vec.argmax([1.5, 2, -3]))print(vec.argmax([]), vec.argmax(null))print(vec.argmax([float("nan"), 2, 1]), vec.argmax([float("nan"), float("nan")]))print(vec.argmax([1, math.inf, 2]))output
0 1null null1 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.argmax([1, null]))output
line 1: `vec.argmax` expects a list of numbers, but item 1 is nullChaining
let names = ["ann", "bob", "cy"]let scores = [71, 88.5, 64]print(names[vec.argmax(scores)])print(scores | vec.argmax)output
bob1See also
vec.argmin, vec.argsort, max, index_of
Thread
Thread 0 posts
On vec.argmax(): 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