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]

本页目录