How to do elementwise comparison sum without for loop
The for loop makes my program very slow. I would've used np.sum(target==output) but I need the argmax value for each row in the output. How can I speed this up?
The output is a tensor data type
for i, x in enumerate(target):
  if target[i] == torch.argmax(output[i]):
    correct_class += 1


You could vectorize the above using np.argmax's axis argument, to obtain the indices of the maximum value across the rows:
(target==np.argmax(output, axis=1)).sum()

For instance:
output = np.random.choice([0,1],(4,2))
print(output)
array([[1, 1],
       [0, 1],
       [0, 1],
       [0, 1]])
target = np.array([[0,1,0,1]])
(target==np.argmax(output, axis=1)).sum()
# 3

