3

I have this multidimensional matrix:

{{{{a1, a2}, {a3, a4}}, {{b1, b2}, {b3, b4}}}, {{{c1, c2}, {c3, c4}}, {{d1, d2}, {d3, d4}}}}

I would like to convert it into this regular matrix:

{{a1, a2, b1, b2}, {a3, a4, b3, b4}, {c1, c2, d1, d2}, {c3, c4, d3, d4}}

I have tried to use Flatten and Partition, but then I get this result:

{{a1, a2, a3, a4}, {b1, b2, b3, b4}, {c1, c2, c3, c4}, {d1, d2, d3, d4}}

Thanks in advance :-)

Leonid Shifrin
  • 114,335
  • 15
  • 329
  • 420
pvh1987
  • 245
  • 2
  • 4

2 Answers2

4

You can use ArrayFlatten for this:

ArrayFlatten[{{{{a1, a2}, {a3, a4}}, {{b1, b2}, {b3, b4}}},
              {{{c1, c2}, {c3, c4}}, {{d1, d2}, {d3, d4}}}}]

(* {{a1, a2, b1, b2}, {a3, a4, b3, b4}, {c1, c2, d1, d2}, {c3, c4, d3, d4}} *)
Simon Woods
  • 84,945
  • 8
  • 175
  • 324
3

Here is what you need:

Flatten[
   {
      {{{a1, a2}, {a3, a4}}, {{b1, b2}, {b3, b4}}}, 
      {{{c1, c2}, {c3, c4}}, {{d1, d2}, {d3, d4}}}
   }
   , 
   {{1, 3}, {2, 4}}
]

Have a look here for an explanation.

Leonid Shifrin
  • 114,335
  • 15
  • 329
  • 420