Tensors and matrices multiplication I have to prove an equality between matrices $R=OTDO$ where


*

*$R$ is a $M\times M$ matrix

*$O$ is a $2\times M$ matrix

*$T$ is a $M\times M\times M$ tensor

*$D$ is a diagonal $2\times 2$ matrix


The entries of the matrices and the tensor are probabilities so the result should somehow be the consequence of Bayes formula. The problem is that I have no idea how to compute that because I don't know how to use tensors. I had an algebra course about tensor products of vector spaces a long time ago but it was very abstract so I don't know how to multiply tensors in practice.
I'm surprised because the first matrix of the product has $2$ rows, the last one has $M$ columns and yet the result is a $M\times M$ matrix.
Could you explain how to do this? For example, what's the dimension of $OT$? I am familiar with the Kronecker product of matrices, is it useful here?

EDIT
Stupid me... I've spent hours trying to understand this product and... this was a typo. It was $O^TDO$ and the equality was straightforward... I've been confused by the fact that the tensor $T$ did exist and there could be and equality involving it. At least I've learnt a few things about tensors, thank you again for the answers!
 A: The multiplication of a tensor by a matrix (or by a vector) is called $n$-mode product.
Let $\mathcal{T} \in \mathbb{R}^{I_1 \times I_2 \times \cdots \times I_N}$ be an $N$-order tensor and $\mathbf{M} \in \mathbb{R}^{J \times I_n}$ be a matrix. The $n$-mode product is defined as
$$ (\mathcal{T} \times_{n} \mathbf{M})_{i_{1}\cdots i_{n-1}ji_{n+1}\cdots i_N} = \sum \limits_{i_n = 1}^{I_n} \mathcal{T}_{i_{1}i_{2}\cdots i_{n}\cdots i_{N}}\mathbf{M}_{ji_{n}}.$$
Note this is not a standard product like the product of matrices. However, you could perform a matricization of the tensor along its $n$-mode (dimension $n$) and thus effectuate a standard multiplication.
The $n$-mode matricization of $\mathcal{T}$, say $\mathbf{T}_{(n)}$, is  an $I_{n} \times I_{1}\cdots I_{n-1}I_{n+1}\cdots I_{N}$ matrix representation of $\mathcal{T}$. In other words, it is just a matrix form to organize all the entries of $\mathcal{T}.$
Hence, the multiplications below are equivalent
$$\mathcal{Y} = \mathcal{T} \times_{n} \mathbf{M} \iff \mathbf{Y}_{(n)} = \mathbf{M} \mathbf{T}_{(n)}, $$ where $\mathbf{Y}_{(n)}$ is the $n$-mode matricization of the tensor $\mathcal{Y} \in \mathbb{R}^{I_1 \times \cdots \times I_{n-1} \times J \times I_{n+1} \times \cdots \times I_N}$.
For more details, see Tensor Decompositions and Applications.
