Hi,
I am looking for an effective way to convert the indices from topk() into a pairwise array without using any for loop…or the most runtime efficient way possible…?
For example,
import torch
import pdb
x_ = torch.randn(10,1)
key_dist_s = torch.cdist(x_, x_, p=2)
pdb.set_trace()
idx = torch.topk(key_dist_s, k=3, largest=True)
idx_indices = idx.indices
I want to reshape the following idx_indices
tensor([[7, 5, 9],
[4, 0, 8],
[7, 4, 5],
[4, 1 8]])
into something like this without using for-loop…
tensor([[7, 5],
[7,9]
[4, 0],
[4, 8],
[7, 4],
[7,5],
[4, 1]... ])
Can anyone please give a solution ?