title: Get indices of elements in tensor a that are present in tensor b
body: <p>For example, I want to get the indices of elements valued 0 and 2 in tensor <code>a</code>. These values, (0 and 2) are stored in tensor <code>b</code>. I have devised a pythonic way to do so (shown below), but I don't think list comprehensions are optimized to run on GPU, or maybe there is a more PyTorchy way to do it that I am unaware of.</p>
  
  <pre class="lang-py prettyprint-override"><code>import torch
  a = torch.tensor([0, 1, 0, 1, 1, 0, 2])
  b = torch.tensor([0, 2])
  torch.tensor([x in b for x in a]).nonzero()
  
  &gt;&gt;&gt;&gt; tensor([[0],
               [2],
               [5],
               [6]])
  </code></pre>
  
  <p>Any other suggestions or is this an acceptable way?</p>