If you are beginner in PyTorch, I would recommend you to read this blog post about tensor indexing.

  
      
      deeplizard.com
  
  
    

Rank, Axes, and Shape Explained - Tensors for Deep Learning 12

Part 2: Introducing tensors for deep learning and neural network programming.