title: To calculate euclidean distance between vectors in a torch tensor with multiple dimensions
body: <p>There is a random initialized torch tensor of the shape as below.</p>
  <p><strong>Inputs</strong></p>
  <pre><code>tensor1 = torch.rand((4,2,3,100))
  tensor2 = torch.rand((4,2,3,100))
  </code></pre>
  <p><code>tensor1</code> and <code>tensor2</code> are torch tensors with 24 100-dimensional vectors, respectively.</p>
  <p>I want to get a tensor with a shape of <code>torch.size([4,2,3])</code> by obtaining the Euclidean distance between vectors with the same index of two tensors.</p>
  <p>I used <code>dist = torch.nn.functional.pairwise_distance(tensor1, tensor2)</code> to get the results I wanted.</p>
  <p>However, the <code>pairwise_distance</code> function calculates the euclidean distance for the second dimension of the tensor. So <code>dist</code> shape is <code>torch.size([4,3,100])</code>.</p>
  <p>I have performed transpose several times to solve these problems. My code is as follows.</p>
  <pre><code>tensor1 = tensor1.transpose(1,3)
  tensor2 = tensor2.transpose(1,3)
  dist = torch.nn.functional.pairwise_distance(tensor1, tensor2)
  dist = dist.transpose(1,2)
  </code></pre>
  <p>Is there a simpler or easier way to get the result I want?</p>