sorted
Returns a new array with elements sorted in ascending order. The shape is preserved — for multi-dimensional arrays, elements are sorted across the entire flat buffer in row-major order.
Signature
fun <T : Number, D : Dimension> MultiArray<T, D>.sorted(): NDArray<T, D>
Returns: NDArray<T, D> — a new array with the same shape, elements sorted in ascending row-major order.
Example
val a = mk.ndarray(mk[3, 1, 4, 1, 5, 9])
a.sorted() // [1, 1, 3, 4, 5, 9]
val m = mk.ndarray(mk[mk[3, 1], mk[4, 2]])
m.sorted()
// [[1, 2],
// [3, 4]]
28 February 2026