Shortcuts, dim, index) Tensor

Slices the input tensor along the selected dimension at the given index. This function returns a view of the original tensor with the given dimension removed.


If input is a sparse tensor and returning a view of the tensor is not possible, a RuntimeError exception is raised. In this is the case, consider using torch.select_copy() function.

  • input (Tensor) – the input tensor.

  • dim (int) – the dimension to slice

  • index (int) – the index to select with


select() is equivalent to slicing. For example,, index) is equivalent to tensor[index] and, index) is equivalent to tensor[:,:,index].


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources