Append in a list from N lists based on predicted value

all_lists = [list0, list1, list2, list3, list4, list5, list6, list7, list8, list9]

preds = classifier(xs)
_, predicted = torch.max(preds.data, 1)

index1 = predicted.item()
if predicted == ys:
    all_lists[index1].append((xs,ben))

but it only works for a batch_size=1 how can I do this for batch_size>1, so that the data is appended into its corresponding list?

Usually, predicted returns a tensor array. You can iterate through that array and check for each item. I assume you can convert it into .numpy() and use the parallel method to do it more quickly