Multik 0.3.0 Help

Input and output

Overview

Multik provides two groups of I/O tools:

  • In-memory conversions for lists, sets, and primitive arrays (available on all platforms).

  • File I/O for CSV/NPY/NPZ on the JVM.

In-memory conversions

Lists and collections

val a = mk.ndarray(mk[1, 2, 3]) val list = a.toList() // List<Int> val mutable = a.toMutableList() // MutableList<Int> val set = a.toSet() // Set<Int>

For nested lists (D2-D4):

val m = mk.ndarray(mk[mk[1.0, 2.0], mk[3.0, 4.0]]) val list2 = m.toListD2() // List<List<Double>>

Primitive arrays

You can extract a flat primitive array from any ndarray:

val v = mk.ndarray(mk[1, 2, 3]) val ints = v.toIntArray() // IntArray

For 2D-4D arrays, toArray() returns nested primitive arrays:

val mat = mk.ndarray(mk[mk[1.0, 2.0], mk[3.0, 4.0]]) val arr2 = mat.toArray() // Array<DoubleArray>

Similar helpers exist for Long, Float, Double, and complex types.

JVM file I/O

File-based I/O is available on the JVM only. For NPY, you can use mk.read and mk.write. For CSV and NPZ, use the format-specific helpers below.

Format

Read

Write

Dimensions

Notes

NPY

mk.read

mk.write

Any

Numeric types only.

NPZ

mk.readNPZ

mk.writeNPZ

Any

Container for multiple NPY arrays; numeric types only.

CSV

mk.readCSV

mk.writeCSV

1D-2D

Complex values supported with complex dtype.

NPY

val a = mk.ndarray(mk[mk[1.0, 2.0], mk[3.0, 4.0]]) mk.write("matrix.npy", a) val loaded = mk.read<Double, D2>("matrix.npy")

NPZ

mk.writeNPZ("bundle.npz", a) val arrays = mk.readNPZ("bundle.npz")

CSV

mk.writeCSV("matrix.csv", a) val csv = mk.readCSV<Double, D2>("matrix.csv")

Non-JVM platforms

On JS, WASM, and Native, use in-memory conversions and a platform-specific serialization library. A common approach is to convert to primitive arrays or lists and serialize those.

28 February 2026