T=tensor([101,123,414,463][234,903,313,341]...)
train=TensorDataset(T)


Now I would like to update tensor T[0] i.e tensor

T[0]=tensor([101,123,567,463])


for this i have tried as follows:

train_dataloader.Dataset[0].index_copy_(0,tensor([2]),tensor([567])


is it possible to modify this way or not? Any kind of reference is helpful

• If I am not mistaken you cannot access Dataset by index and modify it, same as one cannot access a tensor element by index and modify it May 29 at 9:57
• Is their any other way to handle this May 29 at 10:03
• train_dataloader.Dataset[0] is giving me first row in tensor i.e tensor([101,123,414,463]) May 29 at 10:04
• Is it a tensor though? May 29 at 10:11
• yes, it is a tensor and now I would like update certain values in it May 29 at 10:16

Pytorch DataLoader is a generator, it will generate new batches when iterated through. Hence, as per the best of my knowledge, you can only change the data on the fly. For eg, if you want to replace the first element of your dataset with second element of the datase, you can do something like -

T = torch.tensor(([101,123,414,463],[234,903,313,341]))
train = TensorDataset(T)