polars.Expr.arr.arg_min#

Expr.arr.arg_min() Expr[source]#

Retrieve an index of a minimal value in every sub-array.

When multiple values are equal to the minimum, this function may arbitrarily return the index of any of the minimum values. In this case, the returned index is not guaranteed to be the same across multiple runs.

engine:In MemoryStreamingDistributed
Returns:
Expr

Expression of data type UInt32 or UInt64 (depending on compilation).

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [[1, 2], [2, 1]],
...     },
...     schema={"a": pl.Array(pl.Int64, 2)},
... )
>>> df.with_columns(arg_min=pl.col("a").arr.arg_min())
shape: (2, 2)
┌───────────────┬─────────┐
│ a             ┆ arg_min │
│ ---           ┆ ---     │
│ array[i64, 2] ┆ u32     │
╞═══════════════╪═════════╡
│ [1, 2]        ┆ 0       │
│ [2, 1]        ┆ 1       │
└───────────────┴─────────┘