1
$\begingroup$

This might be an odd way of output, but I want to output this way so I can use the format from my fortran code:

Say I have

t1 = Table[f[x, y], {x, {1, 2, 3}}, {y, {1, 2, 3}}]

t2 = Table[g[x, y], {x, {1, 2, 3}}, {y, {1, 2, 3}}]

which gives

t1 = {{f[1, 1], f[1, 2], f[1, 3]}, {f[2, 1], f[2, 2], f[2, 3]}, {f[3, 1], f[3, 2], f[3, 3]}}

t2 = {{g[1, 1], g[1, 2], g[1, 3]}, {g[2, 1], g[2, 2], g[2, 3]}, {g[3, 1], g[3, 2], g[3, 3]}}

My hope is to output this as two column of data in following form :

f[1,1] g[1,1]

f[1,2] g[1,2]

f[1,3] g[1,3]

$\endgroup$
2
$\begingroup$
t1 = Array[f, {3, 3}];
t2 = Array[g, {3, 3}];

ExportString[Flatten[{t1, t2}, {2, 3}], "Table"]
f[1, 1]   g[1, 1]
f[1, 2]   g[1, 2]
f[1, 3]   g[1, 3]
f[2, 1]   g[2, 1]
f[2, 2]   g[2, 2]
f[2, 3]   g[2, 3]
f[3, 1]   g[3, 1]
f[3, 2]   g[3, 2]
f[3, 3]   g[3, 3]
$\endgroup$
  • 2
    $\begingroup$ (Change ExportString[] to Export[] if one wants the output in a file.) $\endgroup$ – J. M. will be back soon Aug 13 '17 at 6:03
  • $\begingroup$ @J.M. Oh, yes, I forgot to mention that. $\endgroup$ – Mr.Wizard Aug 13 '17 at 6:05
2
$\begingroup$
t1 = Table[f[x, y], {x, {1, 2, 3}}, {y, {1, 2, 3}}] // Flatten
t2 = Table[g[x, y], {x, {1, 2, 3}}, {y, {1, 2, 3}}] // Flatten

Export["data.dat", Transpose[{t1,t2}], "Table"]
$\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.