0
$\begingroup$

When dealing with large matrices I like to store them in the memory once for all, such that when I restart Mathematica I do not have to wait for a very long computational time of order of minutes.

To provide a simple example, my current solution is a "DumpSave"-ing local objects, e.g.

A=Table[i+j,{i,1,4},{j,1,4}];
DumpSave[LocalObject["A"],A];
Get[LocalObject[A]];

This saves the object persistently in the folder: ~/../.Wolfram/Objects.

However I do not quite like this, as I may overwrite some of the file by mistake and when switching from a PC to another I have to calculate the matrix again.

Ideally I would create another auxiliary notebook containing the full expression of the large matrix and just load it along with the main notebook, but most of time sis not possible to do that, as Mathematica is not able to fully expand such matrices.

Would you suggest a suitable alternative?

Thanks

$\endgroup$
  • $\begingroup$ What about using the Export function? $\endgroup$ – Aaron Stevens Jul 27 '17 at 21:12
  • $\begingroup$ Why not DumpSave to a directory of your own choosing and a file name of you own choosing by using a full path name for the file instead of making it a local object? $\endgroup$ – m_goldberg Jul 27 '17 at 22:29
3
$\begingroup$

For large matrices of numeric values, I suggest to export to the MATLAB MAT-format. This is a binary format for matrices (and tensors) only and thus, it is much faster than exporting arbitrary symbols.

file = "data.mat";
A = RandomReal[{-1, 1}, {1000, 1000}];
Export[file, A];
B = Import[file][[1]];
B == A

(* True *)

This writes the matrix to the file "data.mat" in the user's home directory. Of course, the value of file can be changed to any valid filename on your machine.

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.