title: Getting an Error in Pytorch: IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)
body: <p>I seem to be having a problem with my code. The error occurs at:</p>
  
  <pre class="lang-py prettyprint-override"><code>x, predicted = torch.max(net(value).data.squeeze(), 1)
  </code></pre>
  
  <p>I'm not sure what the issue is, and I've tried everything to fix. From my understanding, there seems to be a problem with the tensor dimension. I'm not sure what else to do. Can anyone give me any suggestions or solutions on how to fix this problem? Thank you in advance. </p>
  
  <pre><code>class Network(nn.Module): #Class for the neural network
  def __init__(self):
      super(Network, self).__init__()
      self.layer1 = nn.Linear(6, 10) #First number in the number of inputs(784 since 28x28 is 784.) Second number indicates the number of inputs for the hidden layer(can be any number).
      self.hidden = nn.Softmax() #Activation Function
      self.layer2 = nn.Linear(10, 1) #First number is the hidden layer number(same as first layer), second number is the number of outputs.
      self.layer3 = nn.Sigmoid()
  
  def forward(self, x): #Feed-forward part of the neural network. We will will feed the input through every layer of our network.
      y = self.layer1(x)
      y = self.hidden(y)
      y = self.layer2(y)
      y = self.layer3(y)
      return y #Returns the result
  
  net = Network()
  loss_function = nn.BCELoss()
  optimizer = optim.SGD(net.parameters(), lr=0.01)
  
  for x in range(1): #Amount of epochs over the dataset
  for index, value in enumerate(new_train_loader):
      print(value)#This loop loops over every image in the dataset 
      #actual = value[0]
      actual_value = value[5]
      #print(value.size())
      #print(net(value).size())
      print("ACtual", actual_value)
      net(value)
      loss = loss_function(net(value), actual_value.unsqueeze(0)) #Updating our loss function for every image
      #Backpropogation
      optimizer.zero_grad() #Sets gradients to zero.
      loss.backward() #Computes gradients
      optimizer.step() #Updates gradients
      print("Loop #: ", str(x+1), "Index #: ", str(index+1), "Loss: ", loss.item())
  
  
  right = 0
  total = 0
  for value in new_test_loader:
  actual_value = value[5]
  #print(torch.max(net(value).data, 1))
  print(net(value).shape)
  x, predicted = torch.max(net(value).data.squeeze(), 1)
  total += actual_value.size(0)
  right += (predicted==actual_value).sum().item()
  print("Accuracy: " + str((100*right/total)))
  </code></pre>
  
  <p>I should also mention that i'm using the latest versions.</p>