Remove Tensor Column

Hello!

What would be the best way to remove every other column of this tensor:

tensor([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]])

I am able to zero out every other row, but I am not sure how to remove those columns entirely instead of just setting them to zero.

Best,

Hi Aryan!

Use tensor indexing:

>>> import torch
>>> torch.__version__
'1.9.0'
>>> t = torch.tensor([[ 1, 2, 3, 4, 5],
... [ 6, 7, 8, 9, 10],
... [11, 12, 13, 14, 15]])
>>> t[:, [0, 2, 4]]
tensor([[ 1,  3,  5],
        [ 6,  8, 10],
        [11, 13, 15]])

Best.

K. Frank

Hi Mr. Frank

What would be the best way to scale it up? Like taking out every other column for a 256 x 256 image? Every other row?

Thanks,
Aryan