I tried this,
train_dataset = datasets.CIFAR10(root='./data')
idx = torch.tensor(train_dataset.targets) == 1
dataset.data = dataset.data[idx]
dataset.targets = dataset.targets[idx]

I am getting this error
=>              dataset.targets = dataset.targets[idx]

TypeError: only integer tensors of a single element can be converted to an index