partition
Splits the array into two 1D arrays: the first contains elements for which the predicate is true, the second contains the rest. Supports destructuring into val (matching, rest) = ....
Signature
inline fun <T, D : Dimension> MultiArray<T, D>.partition(
predicate: (T) -> Boolean
): Pair<NDArray<T, D1>, NDArray<T, D1>>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Condition to classify each element. |
Returns: Pair<NDArray<T, D1>, NDArray<T, D1>> — first contains elements where the predicate is true, second contains the rest.
Example
val a = mk.ndarray(mk[1, 2, 3, 4, 5, 6])
val (evens, odds) = a.partition { it % 2 == 0 }
// evens: [2, 4, 6]
// odds: [1, 3, 5]
28 February 2026