Convert list to torch.tensor

list_x = []
x = torch.Size([4,3,32,32])
y = torch.Size([6,3,32,32])
list_x = torch.tensor(list_x)

x and y have different shape of dimension 0.
In this case how to convert list to torch.tensor?

I dont think you can convert it like this .

what result (i.e. tensor shape) you expect to see after adding those two tensors?

Thanks for you answer.
I want to add only inputs that satisfy the conditions.
So the size(dim==0) depends on whether the inputs are satisfied or not.

list_x = []
for batch_idx, input in enumerate(data_loader):
   list_x.append(input) # save input images under some conditions

new_data_loader = DataLoader(list_x, ...)

In this purpose, Is there any soultions ?

Maybe… ?

Thanks for you reply.
I’m using but I think it is too slow.

Actually, if your memory is large enough, you can try this

dataset = torch.empty_like(data_loader.dataset)
cur_ind = 0
for batch_idx, input in enumerate(data_loader):
    dataset[cur_ind:cur_ind+len(input)] = input
    cur_ind += len(input)
new_data_loader = DataLoader(dataset[:cur_ind, ...], ...)

What is data_loader.dataset ?