Multik 0.3.0 Help

distinct

Returns a 1D array containing only the unique elements, preserving first-occurrence order. distinctBy compares elements by the key returned from the selector function.

Signatures

fun <T, D : Dimension> MultiArray<T, D>.distinct(): NDArray<T, D1> inline fun <T, D : Dimension, K> MultiArray<T, D>.distinctBy( selector: (T) -> K ): NDArray<T, D1>

Parameters

Parameter

Type

Description

selector

(T) -> K

Key function — elements with the same key are duplicates.

Returns: NDArray<T, D1> — a 1D array of unique elements in first-occurrence order.

Example

val a = mk.ndarray(mk[1, 2, 2, 3, 1, 4]) a.distinct() // [1, 2, 3, 4] a.distinctBy { it % 2 } // [1, 2] (first odd, first even)
28 February 2026