I want just data without comma and brackets. Even TableForm is not working for me. For example, the general pattern of my table is

t = Table[Table[{m, n}, {m, 1, 10}], {n, 1, 9}]

which gives output in the for {x1,y1},{x2,y2}..... . If I use TableForm it will show output as:

1 2 3  ... 10

But I want output of just two columns for the values of m and n ({m,n}) like

m1 m2
m3 m4

How to do that? Or suggest me how convert the data in the form {{x1,y1},{x2,y2}} in just two columns?

  • $\begingroup$ You've seen Grid[]? $\endgroup$ Jul 23, 2012 at 12:04
  • $\begingroup$ Apart from the fine answers you've already gotten: Flatten[Outer[Composition[Reverse, List], Range[5], Range[6]], 1] // Grid $\endgroup$ Jul 23, 2012 at 12:35
  • 1
    $\begingroup$ My answer was intended to be complementary to acl's. The actual method in both answers is to use Grid after merging the top level of the array (with either Faltten or Join), and he posted first. I am glad that you liked my answer but I would prefer that you accept his. This is by no means required and you are always at liberty to Accept whatever answer you choose; it is simply my request. $\endgroup$
    – Mr.Wizard
    Jul 24, 2012 at 8:32

3 Answers 3

Join @@ Array[{#2, #} &, {5, 6}] // Grid

Tuples@Range@{5, 6} ~Reverse~ {2} // Grid
  • $\begingroup$ Or Join @@ Transpose[Array[List, {6, 5}]] // Grid $\endgroup$ Jul 23, 2012 at 12:29
t = Table[Table[{m, n}, {m, 1, 6}], {n, 1, 5}];
Flatten[t, 1] // Grid

Mathematica graphics

  • 1
    $\begingroup$ Some compaction can be done: t = Table[{m, n}, {n, 1, 5}, {m, 1, 6}];. $\endgroup$ Jul 23, 2012 at 12:09
  • $\begingroup$ @J.M. & acl You both beat me by a few seconds - with the answer and the comment ;-) $\endgroup$ Jul 23, 2012 at 12:12
  • $\begingroup$ @acl how can I export this grid to a .txt file. I need the data without the comas and bracets in the .txt file. $\endgroup$
    – Stratus
    May 9, 2018 at 15:03

Maybe Flatten should work. If you have, e.g. a List like {{a, b}, {c, {d}, e}, {f, {g, h}}}, as a result of a Table[] or something else, using Flatten[{{a, b}, {c, {d}, e}, {f, {g, h}}}] you obtain {a, b, c, d, e, f, g, h}.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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