Skip to content

Retrieve the index of the minimum value in every sub-array

Description

Retrieve the index of the minimum value in every sub-array

Usage

<Expr>$arr$arg_min()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  values = list(1:2, 2:1)
)$cast(pl$Array(pl$Int32, 2))
df$with_columns(
  arg_min = pl$col("values")$arr$arg_min()
)
#> shape: (2, 2)
#> ┌───────────────┬─────────┐
#> │ values        ┆ arg_min │
#> │ ---           ┆ ---     │
#> │ array[i32, 2] ┆ u32     │
#> ╞═══════════════╪═════════╡
#> │ [1, 2]        ┆ 0       │
#> │ [2, 1]        ┆ 1       │
#> └───────────────┴─────────┘