I have a set of arrays I would like to output to some file ArrayStorage.txt s.t. these arrays could be read-in to a separate notebook on a separate kernel. Is there an easy way to export a set of arrays?
Asked
Active
Viewed 421 times
2
halirutan
- 112,764
- 7
- 263
- 474
FaintingWater
- 21
- 1
2 Answers
2
If you want to save definitions, then DumpSave is one way to go:
a = RandomReal[1, 1000];
b = RandomInteger[10, 10000];
c = {blub, boing, ups};
DumpSave["tmp/out.mx", {a, b, c}];
Now you can quit the kernel or restart Mathematica and with
<< "tmp/out.mx"
a, b and c have their old values again.
One thing you should note is that files written by DumpSave can only be read on the same type of computer system on which they were written.
halirutan
- 112,764
- 7
- 263
- 474
0
Another way was suggested by David Bailey on MathGroup late last year (https://groups.google.com/forum/?fromgroups=#!searchin/comp.soft-sys.math.mathematica/david$20bailey%7Csort:date/comp.soft-sys.math.mathematica/lf-EJeiqDwY/eEF29xJUFZwJ).
Briefly, as an alternative to MX files, try
str=OpenWrite[file,BinaryFormat->True];
BinaryWrite[str,magic,"TerminatedString"];
BinaryWrite[str,Compress[{expr,version}],"TerminatedString"];
Close[str];
to save, and
str=OpenRead[file,BinaryFormat->True];
If[BinaryRead[str,"TerminatedString"]==magic,
expr=Uncompress[BinaryRead[str,"TerminatedString"]];
];
Close[str];
to read.
dwa
- 1,939
- 14
- 14
a,bandc, and would like to export them such that you can later re-import them all into the same variables? ie, run something and end up with the same array in each ofa,bandcthat you had earlier? or just one tensor of rank>2? – acl Mar 15 '13 at 00:01