Hi,
It might depend a bit on the memory limitations you have. But the following should work (the sizes are very small for printing purposes):
import torch

b = 2
c = 3

index = torch.rand(b, c).mul(5).long()
desired_candidate = torch.rand(b, 5).mul(5).long()

print(index)
print(desired_candidate)


expanded_size = (b, c, 5)
expanded_index = index.unsqueeze(2).expand(expanded_size)
expanded_desired_candidate = desired_candidate.unsqueeze(1).expand(expanded_size)

mask = expanded_index.eq(expanded_desired_candidate).any(-1)

index[mask] = -1
print(index)

Let me know if it fits your needs !