I have tensor
y=
torch.arange(50).reshape(5,10)
tensor([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
[40, 41, 42, 43, 44, 45, 46, 47, 48, 49]])
and now I want to select elements of y
that their indexes appears in s
such that each row of s
is correspond the the row of y
that I want to selects the elements from. for example if s is
s =
torch.arange(10).reshape(5,2)
tensor([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
the output after slicing (y[s]) should be:
[[0,1],
[12,13],
[24,25],
[36,37],
[48,49]]
- how can I do it?
- I tried y[s], but it is not working, also I know that
s
should have same number of columns - will the gradient be reserved after slicing?