My question is how to turn a 4-level matrix (notice one extra level)
A = {{{{1, 2, 3}, {4, 5, 6}}}, {{{7, 8, 9}, {10, 11, 12}}}};
into the following:
B = {{{1, 2, 3}, {4, 5, 6}}, {{7, 8, 9}, {10, 11, 12}}};
I think Flatten
might do the job but I was unable to understand how it works, especially with these matrix second argument.
So a more general question: is there a way to detect extra levels and eliminate them all together?
I am using Mathematica 10.4.1
B = Flatten[A, 1]
orB = Join @@ A
works. $\endgroup$Flatten
by itself removes allList
s. The second argument specifies which level it should remove. (e.g.2
removes two enclosingLists
). If you put a list or a matrix in the second argument, itFlatten
s those levels only. Here is a good explanation on that: (119). $\endgroup$