title: pytorch compute pairwise difference: Incorrect result in NumPy vs PyTorch and different PyTorch versions
body: <p>Suppose I have two arrays, and I want to calculate row-wise differences between every two rows of two matrices of the same shape as follows. This is how the procedure looks like in numpy, and I want to replicate the same thing in pytorch.</p>
  
  <pre><code>&gt;&gt;&gt; a = np.array([[1,2,3],[4,5,6]])
  &gt;&gt;&gt; b = np.array([[3,4,5],[5,3,2]])
  &gt;&gt;&gt; c = a[np.newaxis,:,:] - b[:,np.newaxis,:]
  &gt;&gt;&gt; print(c)
  [[[-2 -2 -2]
    [ 1  1  1]]
  
   [[-4 -1  1]
    [-1  2  4]]]
  </code></pre>
  
  <p>BTW, I tried the same thing using pytorch, but it does not work. Is there anyway we could accomplish the same thing in pytorch</p>
  
  <pre><code>&gt;&gt;&gt; import torch
  &gt;&gt;&gt; a = torch.from_numpy(a)
  &gt;&gt;&gt; b = torch.from_numpy(b)
  &gt;&gt;&gt; c1 = a[None,:,:]
  &gt;&gt;&gt; c2 = b[:,None,:]
  &gt;&gt;&gt; diff = c1 - c2
  &gt;&gt;&gt; print(diff.size())
  torch.Size([1, 2, 3])
  </code></pre>
  
  <p>I was actually looking for <code>torch.Size([2,2,3])</code>. (P.S. I also tried unsqueeze from pytorch, but it doesn't work).</p>