If I type into Mathematica


It gives me a result that has nested matrices. How do I turn that into a normal matrix without any nesting? Thanks

  • 1
    $\begingroup$ Look at Flatten, Join, et al. ... $\endgroup$
    – ciao
    Jul 2, 2014 at 2:32

2 Answers 2


Depends on what dimension your final matrix is supposed to have. When I should make a guess, I would say you want this

TensorProduct[IdentityMatrix[2], IdentityMatrix[2]] // ArrayFlatten

Mathematica graphics


An alternative approach is to use KroneckerProduct which does not require flattening.

From the docs on TensorProduct:

The KroneckerProduct of matrices is equivalent to the flattening of their TensorProduct to another matrix.

That is, for any two matrices m1 and m2

KroneckerProduct[m1, m2] == ArrayFlatten[TensorProduct[m1, m2]]
(* True *)


m1 = IdentityMatrix[2];
KroneckerProduct[m1, m1] == ArrayFlatten[TensorProduct[m1, m1]]
(* True *)
  • $\begingroup$ Excellent. I've been looking to define such a function. Is there a convenient symbol for it like with the Tensor Product: esc t* esc ? $\endgroup$ Jul 12, 2016 at 20:10
  • 1
    $\begingroup$ @Travis, maybe you can define an input alias such as CurrentValue[$FrontEndSession, {InputAliases, "KrP"}] = RowBox[{"KroneckerProduct[", "\[SelectionPlaceholder]", ",", "\[Placeholder]", "]"}] and use it as Esc KrP Esc to get a template with placeholders. Or, define CirclePlus = KroneckerProduct and us it as matrix1 Esc c+ Esc matrix2. $\endgroup$
    – kglr
    Jul 12, 2016 at 20:33

Your Answer

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

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