Getting a specific vector from a matrix using elements of other vectors
I have 2 vectors:
x = torch.tensor([ 0,  1,  0,  0,  2,  2,  3,  3,  0,  0,  2,  2,  4,  4,  0,  5,  0,  4,
         6,  7,  6,  8,  6,  9,  6, 10,  5, 11,  4, 11,  8, 12, 10, 12,  9, 12,
        13, 14, 15, 16, 17, 14, 17, 18, 19, 16, 19, 18])

y = torch.tensor([ 1,  0,  2,  3,  0,  3,  2,  0,  2,  4,  0,  4,  2,  0,  5,  0,  4,  0,
         7,  6,  8,  6,  9,  6, 10,  6, 11,  5, 11,  4, 12,  8, 12, 10, 12,  9,
        14, 13, 16, 15, 14, 17, 18, 17, 16, 19, 18, 19])

I also have a matrix:
mtx = torch.rand(20,20)

Is there a way to get the corresponding [i,i] vector from the matrix using the 2 vectors?
That is, x[0] = 0, y[0] = 1, so the first element of the vector will be mtx[0,1].
x[1] = 1, y[1] = 0, so the second element of the vector will be mtx[1,0], and so on.
I'm looking for an answer without iterating through the vectors (e.g for element in x...?

You can use fancy indexing:

output_vector = mtx[[x,y]]

where output_vector is the vector of mtx values at the indices in the lists 'x' and 'y' as requested.
