評價此頁

torch.select#

torch.select(input, dim, index) Tensor#

在選定的維度上,沿著給定的索引切片 input 張量。此函式返回一個原始張量的檢視,其中給定的維度已被移除。

注意

如果 input 是稀疏張量,並且無法返回張量的檢視,則會引發 RuntimeError 異常。在這種情況下,請考慮使用 torch.select_copy() 函式。

引數
  • input (Tensor) – 輸入張量。

  • dim (int) – 要切片的維度

  • index (int) – 用於選擇的索引

注意

select() 等同於切片。例如,tensor.select(0, index) 等同於 tensor[index],而 tensor.select(2, index) 等同於 tensor[:,:,index]