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
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityDepends 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
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 theirTensorProduct
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 *)
esc
t*
esc
?
$\endgroup$
Jul 12, 2016 at 20:10
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$
Flatten
,Join
, et al. ... $\endgroup$