chunked
Splits the array into non-overlapping chunks of the specified size, returned as rows of a 2D array. If the total number of elements is not evenly divisible by the chunk size, the last row is padded with zeros.
Signature
fun <T, D : Dimension> MultiArray<T, D>.chunked(size: Int): NDArray<T, D2>
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Number of elements in each chunk. |
Returns: NDArray<T, D2> — a 2D array where each row is a chunk. If the total number of elements is not evenly divisible by size, the last row is padded with zeros.
Example
val a = mk.ndarray(mk[1, 2, 3, 4, 5])
val c = a.chunked(2)
// [[1, 2],
// [3, 4],
// [5, 0]] — last chunk padded with 0
Pitfalls
The last chunk is zero-padded if elements don't divide evenly. Check the original size if this matters.
28 February 2026