filter
Returns a 1D array containing only the elements that satisfy the given predicate. Indexed variants allow filtering based on element position. filterNot inverts the predicate. The result is always 1D regardless of the input dimensionality.
Signatures
inline fun <T, D : Dimension> MultiArray<T, D>.filter(
predicate: (T) -> Boolean
): D1Array<T>
inline fun <T> MultiArray<T, D1>.filterIndexed(
predicate: (index: Int, T) -> Boolean
): D1Array<T>
inline fun <T, D : Dimension> MultiArray<T, D>.filterMultiIndexed(
predicate: (index: IntArray, T) -> Boolean
): D1Array<T>
inline fun <T, D : Dimension> MultiArray<T, D>.filterNot(
predicate: (T) -> Boolean
): D1Array<T>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Condition to match. |
|
| Condition with flat index (1D arrays only). |
|
| Condition with multi-dimensional index. |
Returns: D1Array<T> — a flat 1D array of matching elements.
Example
val a = mk.ndarray(mk[mk[1, 2, 3], mk[4, 5, 6]])
a.filter { it > 3 } // [4, 5, 6]
a.filterNot { it > 3 } // [1, 2, 3]
val b = mk.ndarray(mk[10, 20, 30, 40])
b.filterIndexed { i, v -> i % 2 == 0 } // [10, 30]
28 February 2026