Tensor Dot Product of two tensors of arbitrary order I am currently working on implementing the inner(scalar or dot) product of two tensors of arbitrary order. As far as i understand, you need to make sure, that the last dimension of the first tensor $\pmb A$ matches in size with the first dimension of the second tensor $\pmb B$. The resulting tensor $\pmb C$ then has order r + q - 2, if the first has order r and the second one has order q.
Is the product then just 
$V_{ij...km} = T_{ij....l}\, U_{l.....km} \,$ ?
 A: I think you need to review some of the basic properties of tensors.
Firstly, all of the indices on a tensor have the same "dimension", which is the dimension of the underlying vector space on which the tensor acts - if the first index can take values in $\{1,2,\dots,n\}$ then so can each of the other indices. An order 2 tensor can be represented (relative to a given basis) by a matrix but this will always be a square matrix.
Secondly, summing or "contracting" over a pair of indices only produces another tensor if one index is a contravariant index and the other is a covariant index. Contravariant indices are traditionally written as "upper" or superscript indices; covariant indices are traditionally written as "lower" or subscript indices. Thus
$T^{ij\dots l}U_{l \dots km}$
which is shorthand for
$\displaystyle \sum_{l=1}^n T^{ij\dots l}U_{l \dots km}$
is a tensor but
$T_{ij\dots l}U_{l \dots km}$
is not a tensor. You can certainly calculate the values or "components" of $T_{ij\dots l}U_{l \dots km}$ relative to a given basis, but these values will not transform in a consistent way when you change basis, so $T_{ij\dots l}U_{l \dots km}$ does not represent a physically or geometrically meaningful object. This would be similar to adding up the components of a vector relative to a given basis - you can do the arithmetic, but the resulting quantity is not geometrically meaningful.
You can, however, "raise" and "lower" indices using the metric tensor $g_{ij}$. So if you wanted to contract the final index of $T_{ij\dots l}$ with the first index of $U_{l \dots km}$ to create a tensor, you could use the metric tensor as follows:
$g^{lp}T_{ij\dots p}U_{l \dots km} = T_{ij\dots}^{\quad l} U_{l \dots km} $
which is a tensor because you are contracting a contravariant index with a covariant index.
A: If $T_i$ and $U_p$ are two rank-one-tensors then $$g^{ij}T_iU_j,$$ is their inner product.
For rank-two tensors if $T$ has components $T_{ij}$ and $U$ has components $U_{pq}$ then the rank-four tensor $T\otimes U$ has components $(T\otimes U)_{ijpq}:=T_{ij}U_{pq}$. 
But for the inner product $T\cdot U$ between them, which should be a scalar, this is defined as $$g^{is}g^{jt}T_{ij}U_{st},$$
note the pattern of contractions!
One can easily generalize to arbitrary rank if both of $T$ and $U$ have equal rank.
For the case of unequal ranks it is took $T\cdot U:=0$.
