clip
Returns a new array where every element is clamped to the [min, max] range. Elements below min are set to min; elements above max are set to max.
Signature
fun <T, D : Dimension> MultiArray<T, D>.clip(
min: T, max: T
): NDArray<T, D> where T : Comparable<T>, T : Number
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Lower bound. Elements below are set here. |
|
| Upper bound. Elements above are set here. |
Returns: NDArray<T, D> — a new array with the same shape, all elements in min..max.
Example
val a = mk.ndarray(mk[1, 5, 10, 15, 20])
a.clip(5, 15) // [5, 5, 10, 15, 15]
val m = mk.ndarray(mk[mk[0.0, 0.5], mk[1.0, 1.5]])
m.clip(0.2, 1.0)
// [[0.2, 0.5],
// [1.0, 1.0]]
28 February 2026