Calculates the transpose of a tensor.