2
$\begingroup$

I have three matrices I would like to Join at level 3:

table1= Table[0, {5}, {30}, {4}];
table2= Table[0,{5],{30}];
table3= Table[0,{5],{30}];

My first question would be how to Join the above lists in a way so I get

table4= Table[0, {5}, {30}, {6}];

I have tried this to no avail with the Join command, receiving the error message: "at position 2 is expected to have head List for all expressions at \ level 3", which I take to mean, it cant Join because one table doesn't have a level 3.

My second question would be generally whether I can combine the Join-command for multiple lists but also at a specific level. As in Join[table1,table2,table3,3], which of course does not work.

I am very grateful for any and all help.

Thank you very much, Benjamin

$\endgroup$
2

1 Answer 1

0
$\begingroup$

Join a list with {6, 6, 2} dimensions with a list {6, 6} dimensions

The linked topic is very closely related but answers there except two matrices not more, here are few generalizations:

MapThread[Join[#, {##2}] &, {table1, table2, table3}, 2]

Flatten /@ Thread[{#1, ##2}] & @@@ Transpose[{table1, table2, table3}]
$\endgroup$

Your Answer

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

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