I would recommend searching for NumPy solutions to issues like these, as they are extremely easy to recreate in PyTorch. PyTorch has many of the same functions as NumPy, and you can also use indexing (which is the exact same in both libraries).