title: Filter data in pytorch tensor
body: <p>I have a tensor <code>X</code> like <code>[0.1, 0.5, -1.0, 0, 1.2, 0]</code>, and I want to implement a function called <code>filter_positive()</code>, it can filter the positive data into a new tensor and return the index of the original tensor. For example:</p>
  
  <pre><code>new_tensor, index = filter_positive(X)
  
  new_tensor = [0.1, 0.5, 1.2]
  index = [0, 1, 4]
  </code></pre>
  
  <p>How can I implement this function most efficiently in pytorch?</p>