# Compute a double dot product between two tensors of rank 3 and 2

I would need help to calculate a double dot product between a rank 3 tensor A and a rank 2 tensor B (A:B) using mathematica.

Does someone know how to do that?

=================

Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.
– bbgodfrey
Sep 24 ’15 at 20:18

=================

2

=================

The double dot product is also known as the Frobenius inner product–in other words, it is the result of flattening the matrices and treating them as vectors.

So, here is another way to write it:

A = {
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}},
{{2, 0, 0}, {0, 3, 0}, {0, 0, 1}}
};
B = {{2, 1, 4}, {0, 3, 0}, {0, 0, 1}};

Flatten[A, {{1}, {2, 3}}].Flatten[B] (* -> {40, 14} *)

As far as I’m aware, for double ranked tensors, the double dot product is equal to:

A:B=Trace(A⋅BT)A:B=Trace(A⋅BT) A:B = Trace( A \cdot B^T )

For this reason, a “hacked” solution to your problem would be

A = {{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {{2, 0, 0}, {0, 3, 0}, {0, 0,
1}}} ;
B = {{2, 1, 4}, {0, 3, 0}, {0, 0, 1}};
M = {, };
For[i = 1, i <= 2, i++, M[[i]] = Tr[A[[i]].Transpose[B]]] Here I'm looping on the first index of A and then applying the previous formula. This works but it is not very elegant. You could probably automate the dimension of M instead of hardcoding it like I did. The result will give M={40, 14} 2   If this is the correct interpretation of the double dot product, a much more succinct version of your code is Tr[#.Transpose[B]] & /@ A. – march Sep 25 '15 at 5:51