A question about the way of pytorch indexing variables

Hi !
I found a question that most of the indexing functions ,such as index_copy,index_select,scatter, can only specify one dimension and can’t be used to get a multi-dim part from a multi-dim tensor. Is there any elegant way to do that task ?

You can use advanced indexing (a la numpy) for that. It currently has some limitations, but can work fine in many situations:

a = torch.rand(2, 3, 4, 5)
b = a[:, :, [2, 3], [0, 3]]
a[:, [1, 2], [0, 3], :] = 1