toList
Converts the array to a flat Kotlin List<T> in row-major order. Dimensional variants (toListD2, toListD3, toListD4) produce nested lists that mirror the array's shape.
Signatures
fun <T, D : Dimension> MultiArray<T, D>.toList(): List<T>
fun <T, D : Dimension> MultiArray<T, D>.toMutableList(): MutableList<T>
fun <T> MultiArray<T, D2>.toListD2(): List<List<T>>
fun <T> MultiArray<T, D3>.toListD3(): List<List<List<T>>>
fun <T> MultiArray<T, D4>.toListD4(): List<List<List<List<T>>>>
Returns:
toList()/toMutableList(): flat list of all elements in row-major order.toListD2(),toListD3(),toListD4(): nested lists matching the array's dimensional structure.
Example
val a = mk.ndarray(mk[1, 2, 3])
a.toList() // [1, 2, 3]
a.toMutableList() // mutable [1, 2, 3]
val m = mk.ndarray(mk[mk[1, 2], mk[3, 4]])
m.toList() // [1, 2, 3, 4] (flat)
m.toListD2() // [[1, 2], [3, 4]] (nested)
28 February 2026