Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.index_select function

PyTorch torch.index_select function


PyTorch torch reference manual PyTorch torch reference manual

torch.index_select A function in PyTorch for selecting elements at given indices along a specified dimension.

Function definition

torch.index_select(input, dim, index)


Usage examples

Example

import

torch

x

=

torch.

randn

(

4

,

5

)

Select rows 0 and 2

indices

=

torch.

tensor

(

[

0

,

2

]

)

result

=

torch.

index_select

(

x

,

dim

=

0

,

index

=

indices

)

print

(

"Result shape:"

,

result.

shape

)


PyTorch torch reference manual PyTorch torch reference manual