Getting tensor values of a dataset

Is there a direct way to get tensors of a dataset? To do so, I’m currently wrapping the dataset with a dataloader, iterating over it and extracting tensors for data and the label.

I was wondering whether there’s a more straightforward way of doing this.

You should be able to just iterate over the dataset directly, without requiring a dataloader.

class MyDataset(
    def __init__(self, n): = list(range(n))
    def __len__(self):
        return len(
    def __getitem__(self, idx):

my_dataset = MyDataset(100)
for i in my_dataset:
    print(i, end=",")

1 Like