[solved] 1D Tensor mask error in PyTorch 0.2


The following code replace a number (with probability corrupt_prob) of true labels in the training (or test) data with random labels:

        labels = np.array(self.train_labels if self.train else self.test_labels)
        mask = np.random.rand(len(labels)) <= corrupt_prob
        rnd_labels = np.random.choice(self.n_classes, mask.sum())
        labels[mask] = rnd_labels

In PyTorch 0.2 it gave me the following error:

TypeError: len() of unsized object

The type of labels is [torch.LongTensor of size 60000].

Could anybody help me to fix this please?
Thank you in advance for your help!

Problem solved. It works if I convert the tensor to numpy array as follows:

labels_t = self.train_labels if self.train else self.test_labels
labels = labels_t.numpy()