2

I have Mathematica code split into two notebooks. The first part is supposed to run and output a list of numbers into a text file, using Export. The second part uses ReadList to read numbers from the text file, into a list.

I don't like having to convert the list into text and then convert it back to a list. Is there any other way of exporting data which might make it faster for Mathematica to import it again as a list?

Edit:

Suppose the list output from the second notebook has variables and numbers, is storing the result in a text file still ok? For such a case, here is an example of the output list (the way it looks on the text file):

{1}
{75 + 2*Subscript[x, 10] + Subscript[x, 11]}
{-201 - 4*Subscript[x, 10] - 3*Subscript[x, 11] + Subscript[x, 12]}
{157 + 2*Subscript[x, 10] + 3*Subscript[x, 11] - 3*Subscript[x, 12] + Subscript[x, 13]}
{-Subscript[x, 11] + 3*Subscript[x, 12] - 3*Subscript[x, 13] + 10*Subscript[x, 14]}
{-Subscript[x, 12] + 3*Subscript[x, 13] - 12*Subscript[x, 14]}
{-Subscript[x, 13] + 2*Subscript[x, 14]}

If I need to store expressions, which output format is more apt ?

Pavithran Iyer
  • 981
  • 1
  • 11
  • 16
  • 1
    Or use Put (>>) and Get (<<) with a .m file. – m_goldberg Mar 04 '13 at 22:36
  • 1
    or Export[filename,Compress@lst] and Uncompress@Import[filename] – acl Mar 04 '13 at 23:14
  • 3
    Or Export["filename.mx.gz",lst] – Ajasja Mar 04 '13 at 23:34
  • Why do you need to export/import? Are you opening the data at a later time? All notebooks share the kernel. If you have a list defined then you could just access it directly in the 2nd notebook. – s0rce Mar 05 '13 at 00:05
  • 2
    Sorry I forgot to mention why. The reason is that the First part which outputs a list is a very CPU-intensive process. Hence I wish to run this part on a different machine, and obtain the output list. I can later use the output list for the Second Part (which is essentially just plots) and run that on my personal computer. – Pavithran Iyer Mar 05 '13 at 04:03
  • 2
    @PavithranIyer In that case, it's important to remember that DumpSave is not generically compatible between machines. – Xerxes Mar 05 '13 at 04:42
  • Thanks, I have made an edit by extending the question to a more general case. Is a text file still ok to use, to store the outputs from the first notebook ? – Pavithran Iyer Mar 05 '13 at 17:49
  • @Xerxes I thought the difficulty was between different operating systems, not machines directly? – rcollyer Mar 05 '13 at 18:03
  • 1
    @PavithranIyer It'd be good if you could update the question (including the title) and mention that you want to transfer the information between machines, not just notebook. My first reaction was also that notebooks share the same kernel. – Szabolcs Mar 05 '13 at 18:55
  • This is related: http://mathematica.stackexchange.com/a/1960/12 The Compress approach is probably the fastest cross-platform, cross-version solution. – Szabolcs Mar 05 '13 at 18:56
  • @Szabolcs Compress can become almighty slow for large expressions. – Yves Klett Mar 05 '13 at 20:54
  • Also related: http://mathematica.stackexchange.com/q/4615/131 – Yves Klett Mar 05 '13 at 21:00
  • @Yves What do you use? It was still the fastest I found. It was faster than exporting/importing .m.gz and much faster than .wdx. – Szabolcs Mar 05 '13 at 21:13
  • @Szabolcs importing Compressed files is really fast but I sometimes compress large Graphics expressions and this can take several minutes (compression is very good though). Probably depends on the data, but a plain Put or Export to .m is sometimes much faster. – Yves Klett Mar 05 '13 at 21:45
  • @Yves That's good to know! I only exported large (packed) arrays (with some additional metadata that did not fit the array format). – Szabolcs Mar 05 '13 at 22:18

0 Answers0