title: Can I slice tensors with logical indexing or lists of indices?
body: <p>I'm trying to slice a PyTorch tensor using a logical index on the columns. I want the columns that correspond to a 1 value in the index vector. Both slicing and logical indexing are possible, but are they possible together? If so, how? My attempt keeps throwing the unhelpful error</p>
  <blockquote>
  <p>TypeError: indexing a tensor with an object of type ByteTensor. The
  only supported types are integers, slices, numpy scalars and
  torch.LongTensor or torch.ByteTensor as the only argument.</p>
  </blockquote>
  <h2>MCVE</h2>
  <p>Desired Output</p>
  <pre><code>import torch
  
  C = torch.LongTensor([[1, 3], [4, 6]])
  # 1 3
  # 4 6
  </code></pre>
  <p><strong>Logical indexing</strong> on the columns only:</p>
  <pre><code>A_log = torch.ByteTensor([1, 0, 1]) # the logical index
  B = torch.LongTensor([[1, 2, 3], [4, 5, 6]])
  C = B[:, A_log] # Throws error
  </code></pre>
  <p>If the vectors are the same size, logical indexing works:</p>
  <pre><code>B_truncated = torch.LongTensor([1, 2, 3])
  C = B_truncated[A_log]
  </code></pre>
  <p>And I can get the desired result by repeating the logical index so that it has the same size as the tensor I am indexing, but then I also have to reshape the output.</p>
  <pre><code>C = B[A_log.repeat(2, 1)] # [torch.LongTensor of size 4]
  C = C.resize_(2, 2)
  </code></pre>
  <p>I also tried using a <strong>list of indices</strong>:</p>
  <pre><code>A_idx = torch.LongTensor([0, 2]) # the index vector
  C = B[:, A_idx] # Throws error
  </code></pre>
  <p>If I want contiguous ranges of indices, <strong>slicing</strong> works:</p>
  <pre><code>C = B[:, 1:2]
  </code></pre>