# How to join many columns of data in array?

I have large number of columns of data. How to put in single matrix?

For example, with test data of 1 x 3 matrixs

test[1] = {1, 1, 1}
test[2] = {2, 2, 2}
test[3] = {3, 3, 3}
test[4] = {4, 4, 4}


I use

Array[test, 4, 1, Join]


and get 1 x 12 matrix

{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4}


I want to get 4 x 3 matrix

{{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}

• Don't you already have a 4 x 3 matrix or let's say 2-dimensional array? Commented Jan 23, 2019 at 19:11

## 5 Answers

You can try creating an Array and then Transposing:

In[14]:= Transpose @ Array[test, 4]

Out[14]= {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}

num = 4;
test[#] & /@ Range[num] // Transpose


{{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}

• test /@ Range... will do too.
– Kuba
Commented Jan 23, 2019 at 11:38
Array[test, 4, 1, Transpose[{##}] &]


{{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}

also

Array[test, 4, 1, Flatten[{##}, {2}] &]
Array[test, 4, 1, Thread[{##}] &]


Another possibility:

Array[List /@ test[#] &, 4, 1, Join[##, 2] &]


I hope this helps in creating the array you're asking about.

Var matrix = new int [4, 3];
//this creates an array (of arrays) with 4 rows, 3 columns in each row

IF THE VALUES ARE KNOWN (AS IN YOUR CASE) =
Var matrix = new int [4, 3];
{
{1, 1, 1}
{2, 2, 2}
{3, 3, 3}
{4, 4, 4}
}