How to save an NxNxN array (or matrix) to a file in Julia (or Python)?

I am working on a Jupyter laptop and am currently using Julia

I am trying to save a 3x3x3 array to a text file, so when I include it in another notebook, the array is also a 3x3x3 array.

Any suggestions? Thanks in advance.

+7
multidimensional-array save julia-lang
source share
2 answers

You can use the JLD.jl package (Julia Data):

Pkg.add("JLD") using JLD r = rand(3, 3, 3) save("data.jld", "data", r) load("data.jld")["data"] 

The advantage of the JLD package is that it stores exact type information for each variable.

+8
source share

Well, I admit that I'm a python lover, although Julia is starting to grow on me. Since the old python user has a Julia package that can convert arrays to numpy npz files and then read them as well. Example:

  x = reshape(1:27, 3,3,3) Pkg.add("NPZ") using NPZ npzwrite("TEST.npz",x) 

And now I can later download this file (while I am using the NPZ package):

  y = npzread("TEST.npz") 
+3
source share

All Articles