Tensor assignment

Hi. Please look through the below dummy code. I want to assign dataset[1][1] with x, but its giving an error.

from torch.utils.data.dataset import TensorDataset
import torch

s1 = torch.tensor([1, 11, 21, 31], dtype=torch.long)
s2 = torch.tensor([2, 12, 21, 21], dtype=torch.long)
s3 = torch.tensor([3, 33, 44, 55], dtype=torch.long)

dataset = TensorDataset(s1, s2, s3)

x = dataset[0][1]
dataset[1][1] = x
      1 x = dataset[0][1]
----> 2 dataset[1][1] = x

TypeError: 'tuple' object does not support item assignment

How can I perform such assignment?

After playing around with this for a few minutes, it seems that since TensorDataset is a dataset class and not a tensor itself – it won’t support assignment. You can manipulate the values inside of the tensors that your ‘dataset’ is holding (for example try to subtract one by 2) but assignment of a tuple is not possible (which is what is returned when you index into the dataset)