I've got a really long list that's the result of a complex calculation. I'd like to save it in a way that I can use it again when I start a new session in Mathematica, without having to redo all the previous calculations. Is there a good way to do this? Simply copying and saving it using the short format won't work when you open it with a new kernel. If you copy everything using the 'Show All' option and then assigning it to a new variable, which seems to work, but it's quite lengthy and not very convenient.
Asked
Active
Viewed 110 times
1
1 Answers
3
To answer the comment: DumpSave works by storing the definitions of symbols. These definitions will be restored when you Get the .mx file. So a typical workflow would be:
data = Range[1000000];
DumpSave["datafile.mx", data];
Clear[data]
ByteCount[data]
Get["datafile.mx"]
ByteCount[data]
Note how the Get["datafile.mx"] simply restores the old definition of data. This also works with functions etc.
Sjoerd Smit
- 23,370
- 46
- 75
-
Thank you. I have just figured it out as well. I read somewhere that the saved file may not be compatible with a different computer, operating system, or version of Mathematica. Is there a setting to ensure that it always works on different PCs or versions? – hana Aug 09 '23 at 11:40
-
1No, not for
DumpSave. If you need a platform-independent method, useSave, though this might be inefficient for large data. Large data you can store in a file using the WXF format. So it would be something likeExport["data.wxf", data]anddata = Import["data.wxf"]. – Sjoerd Smit Aug 09 '23 at 11:44

DumpSave? – Sjoerd Smit Aug 08 '23 at 13:35data = Range[1000000]; DumpSave["datafile.mx", data]; loadedData = << datafile.mx; loadedData[[4]] == 4– hana Aug 08 '23 at 18:07Iconize.Also "variable = << filename" is wrong, but "variable = Get[filename]" may work.
– Gustavo Delfino Aug 08 '23 at 18:14