0
$\begingroup$

What should I do to convert a matrix of matrices to a non-nested matrix?

$\left( \begin{array}{cc} \left( \begin{array}{cc} {a_1} & {b_1} \\ {c_1} & {d_1} \\ \end{array} \right) & \left( \begin{array}{cc} {a_2} & {b_2} \\ {c_2} & {d_2} \\ \end{array} \right) \\ \left( \begin{array}{cc} {a_3} & {b_3} \\ {c_3} & {d_3} \\ \end{array} \right) & \left( \begin{array}{cc} {a_4} & {b_4} \\ {c_4} & {d_4} \\ \end{array} \right) \\ \end{array} \right)\to \left( \begin{array}{cccc} {a_1} & {b_1} & {a_2} & {b_2} \\ {c_1} & {d_1} & {c_2} & {d_2} \\ {a_3} & {b_3} & {a_4} & {b_4} \\ {c_3} & {d_3} & {c_4} & {d_4} \\ \end{array} \right)$

$\endgroup$
3
  • 7
    $\begingroup$ ArrayFlatten $\endgroup$ Commented Jun 30, 2022 at 8:31
  • 1
    $\begingroup$ We got an excellent answer pointer, this would be a good opportunity for new members looking to gain some reputation to write up an answer with some nice examples. $\endgroup$ Commented Jun 30, 2022 at 9:06
  • $\begingroup$ mathematica.stackexchange.com/questions/119/… $\endgroup$ Commented Jun 30, 2022 at 19:54

1 Answer 1

4
$\begingroup$

To expand on the comment, this is exactly what ArrayFlatten is designed to do. Straight from the documentation:

ArrayFlatten[{{$m_{11}$,$m_{12}$,...},{$m_{21}$,$m_{22}$,...},...}] creates a single flattened matrix from a matrix of matrices $m_{ij}$

So for your example,

sub[i_] = Partition[Table[Alphabet[][[j]][i], {j, 4}], 2]; m = Partition[Table[sub[i], {i, 4}], 2]; flat = ArrayFlatten[m]; MatrixForm /@ {m, flat} 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.