title: Find number of non-zero elements in a tensor along an aixs
body: <p>I want to find the number of non-zero elements in a tensor along a particular axis. Is there any PyTorch function which can do this?</p>
  
  <p>I tried to use the <a href="http://pytorch.org/docs/master/torch.html?highlight=nonzero#torch.nonzero" rel="nofollow noreferrer">nonzero()</a> method in PyTorch.</p>
  
  <pre><code>torch.nonzero(losses).size(0)
  </code></pre>
  
  <p>Here, <code>lossess</code> is a tensor of shape <code>64 x 1</code>. When I run the above statement, it gives me the following error.</p>
  
  <pre><code>TypeError: Type Variable doesn't implement stateless method nonzero
  </code></pre>
  
  <p>But if I run, <code>torch.nonzero(losses.data).size(0)</code>, then it works fine. Any clue, why this is happening or what the error means?</p>