Solved by ptrblck in post #35 
              
              
                Try to use __setattr__ and __getattribute__: 

class MyDataset(Dataset):
    def __init__(self):
        for i in range(32):
            self.__setattr__('data_{}'.format(i), torch.tensor(i))
        
    def __getitem__(self, index):
        return [self.__getattribute__('data_{}'.format(i)) for i …