# Produce 1-line matrices from a set of vectors

I know this is a simple question, but I am really new to Mathematica.

If I have elements a = {1, 2} and b = {2, 3}, I can simply type

S = {{a}, {b}}


and get a set formed by 1-line matrices, a and b. But if I have 73 numbered elements,like w1, w2, ..., w73, this would take a while. With

S = Table[Symbol["w" <> ToString[i]], {i, 1, 73}]


I don't get exactly what I want. The output is like {w1, ..., w73} instead of {{w1}, ..., {w73}}.

S=Table[Symbol["w" <> ToString[i]], {i, 1, 73}];
S = List /@ S;
S // Short


{{w1}, {w2}, {w3}, {w4}, {w5}, {w6}, << 61 >>, {w68}, {w69}, {w70}, {w71}, {w72}, {w73}}

Alternatively,

S=Table[{Symbol["w" <> ToString[i]]}, {i, 1, 73}];
S // Short


{{w1}, {w2}, {w3}, {w4}, {w5}, {w6}, << 61 >>, {w68}, {w69}, {w70}, {w71}, {w72}, {w73}}

There are probably much better ways of handling your data than to define 73 different variables with names like w1, w2, ... w73. For example, if you define them as either a function or an array, then you can index into them and combine them in simple ways. Here's an example where w and w and etc are defined:

w[n_] := {n, n^2};


I'll just define them this way, but you could have them read in as data or created them in any fashion (just as you would have previously defined w1, w2, ... w73). Now you can make your output:

Table[w[i], {i, 1, 5}]
{{1, 1}, {2, 4}, {3, 9}, {4, 16}, {5, 25}}


or use Map:

w[#] & /@ Range


to get the same output. If you wish another level of brackets, this can be accomplished with Table[{w[i]}, {i, 1, 5}] or with {w[#]} & /@ Range.

• +1 for the tip ;-) – Filburt Sep 28 '17 at 22:43
• The output is not what I was looking for. The output should be {{{1,1}}, {{2,4}},{{3,9}},{{4,16}},{{5,25}}}. Can you change your code to get this? – Filburt Sep 29 '17 at 2:00
• Yest, we can just write Table[{w[i]}, {i, 1, 5}] =D – Filburt Sep 29 '17 at 2:13
fun[n_Integer?Positive] := Thread[{#, #^2} &[Range[1, n]]]


Thread is a faster option than Table or Map in this case