Torch, how to select a subset of a tensor?

2019-08-10 01:27发布

问题:

For example, I have a tensor t = torch.rand(10,1). And I want to select the tensor subset of at the rows of {1,3,7,9} and concatenate them as new tensor. Is there any elegant way? Thank you.

回答1:

There's :index method:

tens = torch.rand(10,1)
ind = torch.LongTensor{1,3,7,9}
subset = tens:index(1, ind)


标签: lua torch