Matrix Multiplication Dimension - but with tensors

60 Views Asked by At

Matrices

If I have two matrices $A\in\mathbb{R}^{n\times m}$ and $B\in\mathbb{R}^{m\times p}$ I only require the number of columns of $A$ and the number of rows of $B$ to the the same to do matrix multiplication. The resulting dimension can be found by "eliminating" this common dimension $$ AB \in\mathbb{R}^{n\times p} $$

Tensors

Suppose now I have some three-dimensional tensors $C\in\mathbb{R}^{n\times m\times p}$ and $D\in\mathbb{R}^{q\times r\times s}$. I would like to compute $$ CD $$

What dimensionality requirements do we need and what is the dimension of the resulting tensor after doing tensor multiplication?

My intuition is that we require $m=q$ for this to work.