Возможно, вы захотите использовать torch.gather
- «Собирает значения вдоль оси, заданной dim.»
t = torch.tensor([[-0.2, 0.3],
[-0.5, 0.1],
[-0.4, 0.2]])
idxs = np.array([1,0,1])
idxs = torch.from_numpy(idxs).long().unsqueeze(1)
# or torch.from_numpy(idxs).long().view(-1,1)
t.gather(1, idxs)
tensor([[ 0.3000],
[-0.5000],
[ 0.2000]])
Здесь ваш индекс - массив numpy поэтому вы должны преобразовать его в LongTensor.