Multik 0.3.0 Help

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

min

T

Lower bound. Elements below are set here.

max

T

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