torch.take¶ torch.take(input, index) → Tensor¶ 返回一個新張量,其中包含來自給定索引處的 input 元素的元素。輸入張量將被視為一維張量。結果張量與索引具有相同的形狀。 引數 input (Tensor) – 輸入張量。 index (LongTensor) – 張量的索引 示例 >>> src = torch.tensor([[4, 3, 5], ... [6, 7, 8]]) >>> torch.take(src, torch.tensor([0, 2, 5])) tensor([ 4, 5, 8])