If there are lists with different lengths of sublists like below,
list1 = {{{1, 2, 3, 4}, {11, 12, 13, 14}, {22, 23, 24, 25}}, {{-1, -2, -3, -4}, {-11,-12,-13, -14}, {-22, -23, -24, -25}, {-41, -42, -43,-44}}, {{100, 200, 300, 400}, {-100, -200, -300, -400}}}
How can I combine or delite each element from sublists?Question 1. I have another data of
list2 = {a1, a2, a3},
correspond to list1.So I want to combine list2 to each sub element of
list1;
newlist = {{{1, 2, 3, 4, a1}, {11, 12, 13, 14, a1}, {22, 23, 24, 25, a1}}, {{-1, -2, -3, -4, a2}, {-11, -12, -13, -14, a2}, {-22, -23, -24, -25, a2}, {-41, -42, -43, -44, a2}},{{100, 200, 300, 400, a3}, {-100, -200, -300, -400, a3}}}
How can I get newlist? I know I can append a1 to lsmall,
lsmall = {{1, 2, 3, 4}, {11, 12, 13, 14}, {22, 23, 24, 25}}
by
Append[lsmall[[#]], {a1}] & /@ Range[Length[lsmall]]
However newlist cannot get by
Append[lsmall[[#1, #2]], {list2[[#1]]}] & /@ [Range[Length[lsmall]], [Range[Length[lsmall[[#1]]]]]
... I' m in trouble.
Question2 After I get
newlist = {{{1, 2, 3, 4, a1}, {11, 12, 13, 14, a1}, {22, 23, 24, 25, a1}}, {{-1, -2, -3,-4, a2}, {-11, -12, -13, -14, a2}, {-22, -23, -24, -25, a2}, {-41, -42, -43, -44, a2}},{{100, 200, 300, 400, a3}, {-100, -200, -300, -400, a3}}}
in Question 1, I also want to extract 2 dimensional sub lists, such as
ext1 = {{{1, a1}, {11, a1}, {22, a1}}, {{-1, a2}, {-11, a2}, {-22, a2}, {-41, a2}},{{100, a3}, {-100, a3}}}
... (combination of 1 st and last element) or
ext2 ={{{2, 3}, {12, 13}, {23, 24}}, {{-2, -3}, {-12, -13}, {-23, -24}, {-42, -43}},{{200, 300}, {-200, -300}}}
... (combination of 2 nd and 3 rd element)
I thought
For[i = 1, i <= Length[newlist], i++,
For[j = 1, j <= Length[newlist[[i]]], j++,
ext1 = Transpose[{newlist[[i]][[j]][[All, 1]],
newlist[[i]][[j]][[All, 1]]}];]] Return[ext1]
But it didn't work at all.