title: Why does nn.CrossEntropyLoss throw "TypeError: iteration over a 0-d tensor" when I verify inputs to be non-0-dimensional?
body: <p>I am using PyTorch version 1.5.0. 
  When I pass an input torch tensor of size [8,21,400,400] with a target of size [8,400,400], the program raises a TypeError: iteration over a 0-d tensor. However, the dimensions of the arguments are 4 and 3 respectively. </p>
  
  <p>What could be causing this error?</p>
  
  <p>The traceback points to torch\tensor.py's <strong>iter</strong> function. </p>
  
  <pre><code>Traceback (most recent call last):
    File "train.py", line 108, in &lt;module&gt;
      loss, accuracy = lossLayer(pred2, targetBatch)
    File "C:\Users\PC\anaconda3\lib\site-packages\torch\tensor.py", line 462, in __iter__
      raise TypeError('iteration over a 0-d tensor')
  TypeError: iteration over a 0-d tensor
  </code></pre>