I have a list:
list =
{
{{1,1,{1,1}},{1,2,{2,2}},{1,3,{3,3}},{1,4,{4,4}},{1,5,{5,5}}},
{{2,1,{1.01,1.01}},{2,2,{2.01,2.01}},{2,3,{3.01,3.01}},{2,4,{4.01,4.01}},{2,5,{5.01,5.01}}},
{{3,1,{1.02,1.02}},{3,2,{2.02,2.02}},{3,3,{4.02,4.02}},{3,4,{5.02,5.02}}},
{{4,1,{1.52,1.52}},{4,2,{2.03,2.03}},{4,3,{3.52,3.52}},{4,4,{4.03,4.03}},{4,5,{5.03,5.03}}},
{{5,1,{1.53,1.52}},{5,2,{2.53,2.53}},{5,3,{3.53,3.53}},{5,4,{4.53,4.53}},{5,5,{5.054,5.54}}},
{{6,1,{1.54,1.54}},{6,2,{3.53,3.53}},{6,3,{3.54,3.54}},{6,4,{4.54,4.54}},{6,5,{6.054,6.54}}}
};
Now I want to prepend to each sublist item a -1, so that I get:
{
{{-1,1,1,{1,1}},{-1,1,2,{2,2}},{-1,1,3,{3,3}},{-1,1,4,{4,4}},{-1,1,5,{5,5}}},
{{-1,2,1,{1.01,1.01}},{-1,2,2,{2.01,2.01}},{-1,2,3,{3.01,3.01}},{-1,2,4,{4.01,4.01}},{-1,2,5,{5.01,5.01}}},
{{-1,3,1,{1.02,1.02}},{-1,3,2,{2.02,2.02}},{-1,3,3,{4.02,4.02}},{-1,3,4,{5.02,5.02}}},
{{-1,4,1,{1.52,1.52}},{-1,4,2,{2.03,2.03}},{-1,4,3,{3.52,3.52}},{-1,4,4,{4.03,4.03}},{-1,4,5,{5.03,5.03}}},
{{-1,5,1,{1.53,1.52}},{-1,5,2,{2.53,2.53}},{-1,5,3,{3.53,3.53}},{-1,5,4,{4.53,4.53}},{-1,5,5,{5.054,5.54}}},
{{-1,6,1,{1.54,1.54}},{-1,6,2,{3.53,3.53}},{-1,6,3,{3.54,3.54}},{-1,6,4,{4.54,4.54}},{-1,6,5,{6.054,6.54}}}
}
To do that I could use:
Prepend[#, -1] & /@ list[[#]] & /@ Range[Length[list]]
Do you know another solution for that?
ArrayPad[list, {0, 0, {1, 0}}, -1]-- this may still prove useful in other applications. In this case we would needArrayPad[#, {0, {1, 0}}, -1] & /@ listwhich seems clumsy compared to other methods. – Mr.Wizard Sep 13 '17 at 13:14ArrayFlatten[{{-1, #}}] & /@ list(see https://stackoverflow.com/a/2274679/499167) – user1066 Sep 13 '17 at 19:52