# Working with tables having sub-table structure

Consider two tables

Tab1 = Table[{{RandomReal[{0, 1}],
RandomReal[{0, 1}]}, {RandomReal[{0, 1}],
RandomReal[{0, 1}]}, {RandomReal[{0, 1}],
RandomReal[{0, 1}]}}, {i, 1, 5, 1}];
Tab2 = Table[{{RandomReal[{0, 1}],
RandomReal[{0, 1}]}, {RandomReal[{0, 1}],
RandomReal[{0, 1}]}}, {i, 1, 5, 1}];


Their rows are also tables:

Tab2//TableForm I would like to make several manipulations with the tables:

1. Combine the tables in a way such that their sub-tables will be merged. The ugly realization (in the sense that it may be slow if Tab1 has a large size) is

TabJoined=Table[Join[Tab1[[i]],Tab2[[i]]],{i,1,Length[Tab1],1}];

2. Extract only the first row from each sub-table of Tab1. The ugly realization is

TabRowExtracted=Table[Tab1[[i]][],{i,1,Length[Tab1],1}];

3. Multiply each 2nh element of the second row of Tab1 by 2:

TabSecondElementMultiplied=Table[{Tab1[[i]],{Tab1[[i]][][],2*Tab1[[i]][][]},Tab1[[i]][]},{i,1,Length[Tab1],1}];

Could you please tell me whether there are faster realizations of these tasks?

• One can also use Tab1=RandomReal[{0,1},{5,3,2}]; Tab2=RandomReal[{0,1},{5,2,2}];. Oct 26, 2022 at 9:19
• @user293787 : thanks! Oct 26, 2022 at 9:31

Join[Tab1,Tab2,2]
Tab1[[;;,2]]
MapAt[2*#&,Tab1,{All,2,2}]


That's what I understand from the description in the post. Please provide feedback, if I have not understood it correctly.

SeedRandom;
Tab1 = RandomReal[{0, 1}, {5, 3, 2}];
Tab2 = RandomReal[{0, 1}, {5, 2, 2}];


## Combine the tables in a way such that their sub-tables will be merged

(TabJoined =
Transpose@Catenate[{Transpose@Tab1, Transpose@Tab2}]) // MatrixForm Extract only the first row from each sub-table of Tab1

MatrixForm /@ {Tab1, Tab1[[All, All, 1]]} Multiply each 2nd element of the second row of Tab1 by 2 