createAlignedNDArray
Signature
inline fun <reified T : Number> Multik.createAlignedNDArray(
data: List<List<T>>, filling: Double = 0.0
): D2Array<T>
inline fun <reified T : Number> Multik.createAlignedNDArray(
data: List<List<List<T>>>, filling: Double = 0.0
): D3Array<T>
inline fun <reified T : Number> Multik.createAlignedNDArray(
data: List<List<List<List<T>>>>, filling: Double = 0.0
): D4Array<T>
Each variant also has an Array overload that delegates to the List version.
Parameters
Parameter | Type | Description |
|---|---|---|
| nested List or Array | Ragged nested collection. Inner sequences may have different lengths. |
|
| Value used to pad shorter sequences to the maximum length at each depth. Converted to |
Returns: D2Array<T>, D3Array<T>, or D4Array<T> depending on nesting depth.
Throws: IllegalArgumentException if data is empty.
Example
val ragged = listOf(
listOf(1, 2, 3),
listOf(4, 5),
listOf(6)
)
val aligned = mk.createAlignedNDArray(ragged)
// [[1, 2, 3],
// [4, 5, 0],
// [6, 0, 0]]
val padded = mk.createAlignedNDArray(ragged, filling = -1.0)
// [[1, 2, 3],
// [4, 5, -1],
// [6, -1, -1]]
28 February 2026