How to merge tensor batches!


I have a tensor with size (16, 3, 280, 280), and I want to merge the batches to be added as channels. So, the last size is (48, 280, 280). Is there a way to do it (ex: built-in function in pytorch)? I found function called stack but it accepts tuple of tensors, and I don’t want to iterate over the batch size. I would rather prefer if there is another way to do the process in bulk.

how about using reshape?

For example :

x = torch.rand(16, 3, 280, 280)
x = x.reshape(48, 280, 280)
1 Like

I thought it might change the order of some values in inside, so I didn’t try it but It works fine. Thank you.

1 Like