title: Why I am getting this error when i am trying to run this and getting the loss training?
body: <p>Why I am facing this error when I am trying to run this code below?
  the error is in this section of the code (predictions.append(prd.item())) still not understand why its error? </p>
  
  <pre><code>train_accuracies = []
  train_loss = []
  predictions = []
  for epoch in range(10):
      iterations = 0
      running_loss = 0
      for i,(inputs,labels) in enumerate(train_loader):
  
          iterations+=1
  
          inputs = inputs.float()
          labels = labels.long()
  
          # Feed Forward
          output = net(inputs)
          # Loss Calculation
          loss = criterion(output, labels)
  
          running_loss = running_loss + loss.item()    
          _, prd = torch.max(output, dim = 1)
          predictions.append(prd.item())
          accuracy = (prd == labels).float().mean()
          train_accuracies.append(accuracy.item())
          train_loss.append(running_loss / iterations)
  
          #i = i.view(i.shape[0], -1)
  
          # Clear the gradient buffer (we don't want to accumulate gradients)
          optimizer.zero_grad()
          # Backpropagation 
          loss.backward()
          # Weight Update: w &lt;-- w - lr * gradient
          optimizer.step()
  
  
  
          #print("Epoch [{}][{}/{}], Loss: {:.3f}".format(epoch, i, len(train_loader), running_loss / iterations))
          print("Epoch [{}][{}/{}], Loss: {:.3f}".format(epoch ,i , len(train_loader), running_loss))
  </code></pre>
  
  <p>The error is: </p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  
  &lt;ipython-input-41-8bf6c94dc5dd&gt; in &lt;module&gt;()
       19         running_loss = running_loss + loss.item()
       20         _, prd = torch.max(output, dim = 1)
  ---&gt; 21         predictions.append(prd.item())
       22         accuracy = (prd == labels).float().mean()
       23         train_accuracies.append(accuracy.item())
  
  ValueError: only one element tensors can be converted to Python scalars
  </code></pre>
  
  <p>How to fix this? </p>