How can I slice a PyTorch tensor with another tensor?
问题 I have: inp = torch.randn(4, 1040, 161) and I have another tensor called indices with values: tensor([[124, 583, 158, 529], [172, 631, 206, 577]], device='cuda:0') I want the equivalent of: inp0 = inp[:,124:172,:] inp1 = inp[:,583:631,:] inp2 = inp[:,158:206,:] inp3 = inp[:,529:577,:] Except all added together, to have a .size of [4, 48, 161] . How can I accomplish this? Currently, my solution is a for loop: left_indices = torch.empty(inp.size(0), self.side_length, inp.size(2)) for batch