How can I do tensor contractions with pytorch? The most similar operation that I found is torch.matmul, but actually it is a batched matrix product rather than a contraction. I cannot choose the indicies over which the contraction is done with torch.matmul. Eigen::Tensor has the operation 5. I also found the operation 8 in numpy whereas it is slightly restricted than the one in Eigen::Tensor. I’m looking for a corresponding one in pytorch.