Skip to contents

Returns the index of the maximum value along a single dimension. Ties are broken by returning the smallest index.

Usage

prim_argmax(operand, dim, drop = TRUE)

Arguments

operand

(arrayish)
Arrayish value of any data type.

dim

(integer(1))
Dimension along which to find the index of the maximum.

drop

(logical(1))
If TRUE (default) the reduced dimension is removed; if FALSE it is kept with size 1.

Value

arrayish of dtype i32
Same shape as operand with dim removed (or set to 1 if drop = FALSE).

Implemented Rules

  • stablehlo

  • reverse

StableHLO

Lowers to a variadic stablehlo::hlo_reduce() over (values, indices) with a (value > value | (value == value & idx < idx)) selector.

Examples

prim_argmax(nv_array(c(3, 1, 4, 1, 5)), dim = 1L)
#> AnvlArray
#>  5
#> [ CPUi32{} ]