Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I type into Mathematica

TensorProduct[IdentityMatrix[2],IdentityMatrix[2]]

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

share|improve this question
1  
Look at Flatten, Join, et al. ... –  rasher Jul 2 at 2:32

2 Answers 2

up vote 8 down vote accepted

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

share|improve this answer

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 *)

So,

m1 = IdentityMatrix[2];
KroneckerProduct[m1, m1] == ArrayFlatten[TensorProduct[m1, m1]]
(* True *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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