# Importing array with complex numbers

This is probably an easy question: I am exporting the results from a longer calculation into a dat-File, then I set the cell to non-evaluatable and put an Import in front, so I can later work with the results, even after closing and reopening the notebook:

results = Import["results.dat"]

(non-evaluatable) results = makeLongCalculation[parameters]
(non-evaluatable) Export["results.dat",results]

doSomethingwithResults[results]


(Is there a more elegant way?)

Now, I have the problem that complex numbers are imported as strings. My results are typically of the form {{0.01,3*10^-6+5*10^-4*I},...}. Is there any more straightforward way than to apply something like ToExpression to the Import? I feel that native Mathemat

• I think you accidentally the sente... ;) Also, it sounds like you need NumberForm – rm -rf Jul 11 '12 at 8:59

Or in concise notation:

results >>   "results.dat";
results = << "results.dat";


You can automate the process slightly, by reading the data in if the file exists and results isn't defined or writing it out otherwise.

If[Head@results === Symbol && FileExistsQ["complex.dat"],
results = << "complex.dat", results >> "complex.dat"]

• As I would like to maintain control (calculation may take8h on 8cores), I will not use the automation here, but nevertheless nice idea. Thanks. (Also to Simon.) – mcandril Jul 11 '12 at 10:06
• @mcandril Thanks, it may be that someone here can reduce that computation time for you. – image_doctor Jul 11 '12 at 14:45
• It is basically just adding up A LOT of complex numbers, for unaproximated Frenel-Huygens principle. I am not sure how much optimisation potential there is and how to pose the question so its relevant. – mcandril Jul 12 '12 at 15:54

You could use Put and Get instead of Export and Import.

Put[results,"results.dat"]
results = Get["results.dat"];