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

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$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.