Reference · Vectors

vec.argmax

signature
vec.argmax(list | null) -> int | null

What 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.5

Edge cases

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 null1

Errors

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 null

Chaining

let names = ["ann", "bob", "cy"]let scores = [71, 88.5, 64]print(names[vec.argmax(scores)])print(scores | vec.argmax)
output
bob1

See also

vec.argmin, vec.argsort, max, index_of

Thread
7Useful? Like it, or add to its thread below.

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