Exporting and reimporting a list of lists changes the dimensions

What is happening is that your data is imported as strings:

dummy = Table[{k, 2*k}, {k, 1, 3}, {m, 1, 3}]
Dimensions[dummy]
Export["~/Desktop/dummy.dat", dummy]; dummyImport = 
 Import["~/Desktop/dummy.dat"]
Dimensions[dummyImport] 
Map[Head, dummy, {-1}]
Map[Head, dummyImport, {-1}]

enter image description here

One way to fix it is to force the save to occur in some particular format:

dummy = Table[{k, 2*k}, {k, 1, 3}, {m, 1, 3}]
Dimensions[dummy]
Export["~/Desktop/dummy.dat", dummy, "MAT"]; dummyImport = 
 Import["~/Desktop/dummy.dat", "MAT"]
Dimensions[dummyImport] 

Map[Head, dummy, {-1}]
Map[Head, dummyImport, {-1}]

enter image description here

Alternatively, DumpSave, which uses an OS-dependent format, may be used to save and reload parts of the environment

DumpSave["~/Desktop/dummy.mx", dummy];
ClearAll[dummy];
dummy
Import["~/Desktop/dummy.mx"]
dummy

Tags:

Import

Export