Matrix multiplication for higher dimensional matrices [duplicate]

This question already has an answer here:

What are the most common pitfalls awaiting new users?

32 answers

I have a matrix like this (myb1):

I would like to get the matrix multiplication of each of the submatrix to itself. For example the first 2×2 matrix
[1212]\begin{bmatrix}1 & 2\\1 & 2\end{bmatrix}
should be multiplied by itself and answer of res2[[1,1]] be [3636]\begin{bmatrix}3 & 6\\3 & 6\end{bmatrix} and so on.

I tried:
for loop (in the picture) and didn’t help

Direct mathematica code: myb1.myb1 and it didn’t work out either

Mathematica Code

myb1[[1, 1]] = {{1, 2}, {1, 2}}

myb1[[1, 2]] = {{2, 3}, {3, 4}}

myb1[[2, 1]] = {{5, 2}, {8, 2}}

myb1[[2, 2]] = {{1, 2}, {1, 2}}

For[i = 1, i <= 2, i++, For[j = 1, j <= 2, j++, res2 = myb1[[i, j]].myb1[[i, j]]; ] ] ================= ================= 1 Answer 1 ================= For the love of this fine site, please post copyable code along with accompanying images the next time! Anyway: myb1 = {{{{1, 2}, {1, 2}}, {{2, 3}, {3, 4}}}, {{{5, 2}, {8, 2}}, {{1, 2}, {1, 2}}}}; Map[MatrixPower[#, 2] &, myb1, {2}] {{{{3, 6}, {3, 6}}, {{13, 18}, {18, 25}}}, {{{41, 14}, {56, 20}}, {{3, 6}, {3, 6}}}} Map[#.# &, myb1, {2}] {{{{3, 6}, {3, 6}}, {{13, 18}, {18, 25}}}, {{{41, 14}, {56, 20}}, {{3, 6}, {3, 6}}}}      I tried your suggestion -- can you look at my edit and tell me how to get the final answer instead of dots between matrices inside the big matrix – kpnane Jul 4 '15 at 2:47 3   Yes: don't use MatrixForm[]. Then, try again. – J. M.♦ Jul 4 '15 at 2:49