快捷方式

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])

文件

訪問 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源