I’ve found a way to do build a list that permits retrieving this key-pair value but this may not be the best solution…
coordinate = (torch.isnan(train_data) != True).squeeze(-1).nonzero()
# tensor([[0, 0], [0, 1],[0, 2],[4, 1], [5, 2],[6, 0]])
idx_pair = []
for id_va in set(coordinate[:, 1]):
    all_tidx = torch.where((coordinate == id_va))[0]
    for x, y in zip(all_tidx, all_tidx[1:]):
        idx_pair.append(torch.stack((coordinate[x][0], coordinate[y][0], coordinate[y][1])))
idx_pair = torch.stack(idx_pair)
# output = tensor([[0, 3, 0],
#        [1, 4, 1],
#        [2, 5, 2],
#        [5, 6, 2]])