title: PyTorch [1 if x > 0.5 else 0 for x in outputs ] with tensors
body: <p>I have a list outputs from a sigmoid function as a tensor in PyTorch</p>
  
  <p>E.g</p>
  
  <pre><code>output (type) = torch.Size([4]) tensor([0.4481, 0.4014, 0.5820, 0.2877], device='cuda:0',
  </code></pre>
  
  <p>As I'm doing binary classification I want to turn all values bellow 0.5 to 0 and above 0.5 to 1.</p>
  
  <p>Traditionally with a NumPy array you can use list iterators:</p>
  
  <pre><code>output_prediction = [1 if x &gt; 0.5 else 0 for x in outputs ]
  </code></pre>
  
  <p>This would work, however I have to later convert output_prediction back to a tensor to use</p>
  
  <pre><code>torch.sum(ouput_prediction == labels.data)
  </code></pre>
  
  <p>Where labels.data is a binary tensor of labels.</p>
  
  <p>Is there a way to use list iterators with tensors?</p>