title: Slicing pytorch tensors and use of data_ptr()
body: <pre><code>a = tensor([[ 1,  2,  3,  4,  5],
          [ 6,  7,  8,  8, 10],
          [11, 12, 13, 14, 15]])
  </code></pre>
  <p>I have a <code>torch</code> tensor and I need to index a tensor <code>c</code> such that <code>c = [[3], [8], [13]]</code></p>
  <p>So I did <code>c = a[:,[2]]</code> which gave me the expected answer, but it still failed on the autograder.
  The autograder uses a check function as follows -</p>
  <pre><code>def check(orig, actual, expected):
    expected = torch.tensor(expected)
    same_elements = (actual == expected).all().item() == 1
    same_storage = (orig.storage().data_ptr() == actual.storage().data_ptr())
    return same_elements and same_storage
  
  print('c correct:', check(a, c, [[3], [8], [13]]))
  </code></pre>
  <p>I tried debugging it and it turns out that <code>same_storage</code> is false, I don't understand why <code>orig.storage().data_ptr() == actual.storage().data_ptr()</code> should be <code>True</code>, and how it makes a difference.</p>
  <p><strong>Update</strong>
  I was able to get the correct answer by doing <code>c = a[:, 2:3]</code> instead of <code>c = a[:, [2]]</code> what is the difference?</p>