title: Masking tensor of same shape in PyTorch
body: <p>Given an array and mask of same shapes, I want the masked output of the same shape and containing 0 where mask is False.</p>
  
  <p>For example,</p>
  
  <pre><code># input array
  img = torch.randn(2, 2)
  print(img)
  # tensor([[0.4684, 0.8316],
  #        [0.8635, 0.4228]])
  print(img.shape)
  # torch.Size([2, 2])
  
  # mask
  mask = torch.BoolTensor(2, 2)
  print(mask)
  # tensor([[False,  True],
  #        [ True,  True]])
  print(mask.shape)
  # torch.Size([2, 2])
  
  # expected masked output of shape 2x2
  # tensor([[0, 0.8316],
  #        [0.8635, 0.4228]])
  </code></pre>
  
  <p>Issue: The masking changes the shape of the output as follows:</p>
  
  <pre><code>#1: shape changed
  img[mask]
  # tensor([0.8316, 0.8635, 0.4228])
  </code></pre>