# Flatten sublists within a bigger list

Really sorry if this question is a duplicate. I couldn't find exactly what I was looking for.

Here is a list I have:

{{{0. + 0.1875 I, 0. + 0.105469 I, 0. + 0.03125 I, 0. + 0.00390625 I,
0. + 0. I, 0. + 0. I, 0. + 0. I, 0. + 0. I}, {0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0}}, {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0,
0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}, {{0, 0, 0, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}}


Here it is again in MatrixForm:

I would like to join all triplets of sub arrays in each colums so as to have only three long columns an end up with a 2-dimensional array.

Can't seem to find a way using Flatten. Any help would be awesome!

• To put it more plainly, I wish to flatten every column independently. Oct 31, 2016 at 9:55
• @Feyre Nope, this just gives a 2d array with all the small columns next to one another :( Oct 31, 2016 at 10:00
• Transpose@(Join @@@ Table[list[[i]], {i, 3}]) Oct 31, 2016 at 10:10
• One way is Flatten /@ data // Transpose, there could potentially be even simpler ways. Oct 31, 2016 at 10:26
• Many thanks to both of you :) Oct 31, 2016 at 10:32

## 2 Answers

Flatten can be used to reshape dimensions by making use of its second parameter.

Flatten[#, {2, 3}] &@Transpose@data// MatrixForm


Transpose places your columns in rows then Flatten flattens over dimension 2 (each cell in each row - these contain a sub-list) and then over dimension 3 (each value in each sub-list of each row). This gives the the three columns you are seeking.

Hope this helps.

• +1 That can simplified to Flatten[data, {1, 3}] // MatrixForm. Oct 31, 2016 at 17:54
• @WReach Great improvement. Thanks. Oct 31, 2016 at 20:43

If it isn't closed, it should get an answer. As far as I can tell the shortest way is

Join @@@ list // Transpose


or as @C.E. pointed out

Flatten /@ list // Transpose