I have a function with two variables:

f[x_,y_]:=f[x,y] = ...

I calculated some values (they are fractions like 435345345/3424242424) and would like to store the values from x=1 to x=5000 with y=0 in a file, so that I can use them later again in a function g[x]

I exported them:

Export["file.dat", Table[f[x,0],{x,1,5000}]

And then I import them in another file:

data = Import["file.dat", "List"]

Now I can access the fractions in data by using, for example:


Which gives me the fraction that was originally stored in f[7,0]

So far so good, but I would again like to have the values stored in some function g, with the properties that (in new file) g[x] = f[x,0] (in old file) for x between 1 and 5000

I am not really sure how the notation for that would be :-(

Thank you for your help.


1 Answer 1


You are looking for Save or DumpSave

Here is an example:

(*Put some definitions into f*)
f[x_, y_] := f[x, y] = x + y;
Table[f[x, y], {x, 0, 10}, {y, 0, 10}];

(*are the definitions there?*)

(*Save to file*)
Save["f.m", f]

(*Clear all definitions and check that none remain*)

(*Import again*)

  • $\begingroup$ Thank you for your response. How would I save only a specific part of when doing Save["f.m", f], because all data might be big (because the amount of ram mathematica is using after storing the values is 100gb) - I only need f[1,0] to f[5000,0], which is like 40mb when exporting it as a list. $\endgroup$
    – user5988
    Feb 19, 2013 at 11:04
  • $\begingroup$ you can unset the rest as per this question mathematica.stackexchange.com/questions/71/… $\endgroup$
    – Ajasja
    Feb 19, 2013 at 11:27
  • $\begingroup$ (clicked too early, 1 sec..) $\endgroup$
    – user5988
    Feb 19, 2013 at 12:19
  • $\begingroup$ I did it by basically doing it the other way around, by creating, saving and importing a new function g with just the needed values: For[i = 1, i <= 5000, i++, g[i] = f[i, 0]] -- Save["g.m",g] -- Import[g] That worked, thanks again :-) $\endgroup$
    – user5988
    Feb 19, 2013 at 12:36
  • $\begingroup$ You're welcome. $\endgroup$
    – Ajasja
    Feb 19, 2013 at 12:37

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