PyTorch torch.index_select function
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
)
(
"Result shape:"
,
result.
shape
)