First, the example you give is not the “dot product” of two tensors,
as you refer to it in the title of the your thread. Rather, it is element-wise multiplication of two tensors.
If indeed what you want is the diagonal of the element-wise product
of two tensors, it will be more efficient to extract the diagonals of
the two tensors first and then multiply them element-wise: