# Exporting lists with two extensions to files

Continuation of this question: How to export if I need to have two extensions instead of one. E.g., in the previous case one can generate lists labeled L[1], L[2],.....and so on using a loop. But if I have 2 loops and hence two variables and the lists are labeled L[1,1], L[1,2],… then L[2,1], L[2,2],… How do I export them in wdx format?

-

Make some 2D data:

data = RandomInteger[Range@2, {5, 3}];


Create a series of strings to represent the indices of the elements of data:

Array[ToString[#1] <> "_" <> ToString[#2] &, Dimensions@data]


{{"1_1", "1_2", "1_3"}, {"2_1", "2_2", "2_3"}, {"3_1", "3_2", "3_3"}, {"4_1", "4_2", "4_3"}, {"5_1", "5_2", "5_3"}}

Then just add those strings into whatever basename and extension you are using for your files and use that with Save, DumpSave or Export.

-
Since you used Dimensions, perhaps StringJoin[Riffle[ToString/@{##}, "_"]]& would be more universal. –  VF1 Dec 15 '12 at 5:43
@VF1 That looks significantly different enough to be an answer :) –  image_doctor Dec 15 '12 at 10:31

If you have n-dimensional data, then create the names:

names = Array[StringJoin[Riffle[ToString/@{##}, "_"]]&, Dimensions[data]]


Then export each one:

MapThread[Export[#1 <> ".wdx", #2] &, {names, data}, Depth@data - 1]

-