Shortcuts

torch.select

torch.select(input, dim, index) 张量

沿选定维度在给定索引处对 input 张量进行切片。 此函数返回原始张量的视图,并移除给定维度。

注意

如果 input 是一个稀疏张量并且无法返回张量的视图,则会引发 RuntimeError 异常。在这种情况下,请考虑使用 torch.select_copy() 函数。

Parameters
  • 输入 (张量) – 输入张量。

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

  • 索引 (int) – 用于选择的索引

注意

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