How can I randomly shuffle the labels of a Pytorch Dataset?
I am new to Pytorch, and I am having troubles with some technicalities. I have downloaded the MNIST dataset, using the following command:

train_dataset = dsets.MNIST(root='./data', 
                            train=True, 
                            transform=transforms.ToTensor(),
                            download=True)


I now need to run some experiments on this dataset, but using random labels. How can I shuffle/reassign them randomly? 

I am trying to do it manually, but it tells me that " 'tuple' object does not support item assignment". How can I do it then? 

Second question: How can I remove a training point from the dataset? It gives me the same error, when I try to do it. 

Thank you!!

If you only want to shuffle the targets, you can use target_transform argument. For example:

train_dataset = dsets.MNIST(root='./data', 
                            train=True, 
                            transform=transforms.ToTensor(),
                            target_transform=lambda y: torch.randint(0, 10, (1,)).item(),
                            download=True)


If you want some more elaborate tweaking of the dataset,
you can wrap mnist completely

class MyTwistedMNIST(torch.utils.data.Dataset):
  def __init__(self, my_args):
    super(MyTwistedMNIST, self).__init__()
    self.orig_mnist = dset.MNIST(...)  

  def __getitem__(self, index):
    x, y = self.orig_mnist[index]  # get the original item
    my_x = # change input digit image x ?
    my_y = # change the original label y ?
    return my_x, my_y

  def __len__(self):
    return self.orig_mnist.__len__()


If there are elements of the original mnist you want to completely discard, than by wrapping around the original mnist, your MyTwistedMNIST class can return len smaller than self.orig_mnist.__len__() reflecting the amount of actual mnist examples you want to handle. Moreover, you will need to map the new index of examples to the original mnist index.
