Hello
If I understood correctly, you need gather function. I have created an explanation how to use it, I hope it will be  helpful for you: https://medium.com/analytics-vidhya/understanding-indexing-with-pytorch-gather-33717a84ebc4 193
I’m linking my own article but I believe it will be helpful.