TransWikia.com

How to rewrite a tensor as a matrix

Mathematica Asked on October 22, 2021

I put
{TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]}/Sqrt[2]//MatrixForm
and I got
$$
left(
begin{array}{cc}
left(
begin{array}{cc}
left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) & left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) \
left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) & left(
begin{array}{cc}
0 & 0 \
0 & frac{1}{sqrt{2}} \
end{array}
right) \
end{array}
right) & left(
begin{array}{cc}
left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) & left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) \
left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) & left(
begin{array}{cc}
0 & 0 \
0 & 0 \
end{array}
right) \
end{array}
right) \
end{array}
right)
$$

as a result.
I now would like to rewrite this as
$$
left(
begin{array}{cc}
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\
0 & 0 & 0 & frac{1}{sqrt{2}} & 0 & 0 & 0 & 0
end{array}
right)
$$

to calculate eigenvalues of this matrix above.

Could you tell me how?

4 Answers

mat = {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]/Sqrt[2]};

FixedPoint[ArrayFlatten, mat] // MatrixForm

$left( begin{array}{cccccccc} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & frac{1}{sqrt{2}} & 0 & 0 & 0 & 0 \ end{array} right)$

Answered by Suba Thomas on October 22, 2021

mat = {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]/ Sqrt[2]};

ArrayFlatten[ArrayFlatten /@ mat] // MatrixForm

$left( begin{array}{cccccccc} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & frac{1}{sqrt{2}} & 0 & 0 & 0 & 0 \ end{array} right)$

Answered by OkkesDulgerci on October 22, 2021

X = {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]/Sqrt[2]};

Flatten[X, {{1, 3, 5}, {2, 4, 6}}]

(*    {{0, 0, 0, 0, 0, 0, 0, 0},
       {0, 0, 0, 0, 0, 0, 0, 0},
       {0, 0, 0, 0, 0, 0, 0, 0},
       {0, 0, 0, 1/Sqrt[2], 0, 0, 0, 0}}    *)

Answered by Roman on October 22, 2021

Another option

(m = {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]}/Sqrt[2]) // MatrixForm

Mathematica graphics

And now

m1 = ArrayFlatten[m[[1, 1]], 2]
m2 = ArrayFlatten[m[[1, 2]], 2]
Join[m1, m2, 2] // MatrixForm

Mathematica graphics

Answered by Nasser on October 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP