Human-readable externalization for multi-dimensional arrays

I don’t have an answer for you, but I know that when Octave stores an N-dim array in ascii format, it first gives you the number of dimensions N, then the next N numbers are the size of those dimensions, and finally the values. E.g.

x = reshape(1:24, 3,4,2);
save x.dat x

Then the data file it saves looks like

# name: x
# type: matrix
# ndims: 3
 3 4 2
 1 2 3 ... 24

Maybe you could store the data like that, and recreate it? Maybe in JSON you could do something like

{
    "name": "x",
    "type": "Array{Int64, 3}",
    "dims": [3, 4, 2],
    "data": [1, 2, 3, ..., 24]
}

That’s easily human readable, and should give you all the information you need to recreate the array manually.

2 Likes