2
$\begingroup$

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
1........... 
...............
2...Numbers......
..............
9............9

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?

$\endgroup$
3
  • $\begingroup$ You've seen Grid[]? $\endgroup$
    – J. M.'s torpor
    Jul 23 '12 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$
    – J. M.'s torpor
    Jul 23 '12 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 '12 at 8:32
3
$\begingroup$
Join @@ Array[{#2, #} &, {5, 6}] // Grid

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

Mathematica graphics

$\endgroup$
3
  • 1
    $\begingroup$ Some compaction can be done: t = Table[{m, n}, {n, 1, 5}, {m, 1, 6}];. $\endgroup$
    – J. M.'s torpor
    Jul 23 '12 at 12:09
  • $\begingroup$ @J.M. & acl You both beat me by a few seconds - with the answer and the comment ;-) $\endgroup$ Jul 23 '12 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$
    – Diogo
    May 9 '18 at 15:03
0
$\begingroup$

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}.

$\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.