How to indexing specified dimension to a subtensor in pyTorch?

Hi guys,

I’m new to pytorch. I wonder if pytorch support to indexing specified dimensions for example, for a tensor a:

a = torch.FloatTensor([[1, 2, 3], [4, 5, 6]])

I want to select the first and third column as a subtensor.

[[1, 3]
[4, 6]]

I checked documents and discussion but still don’t know how to do it. I need some guidance.


We are modifying our indexing to be on parity with numpy.
In the meanwhile, you can do this:

a.index_select(1, torch.LongTensor([0, 2]))

Worked for me! Thanks a lot:slight_smile: