How to get count number of equal elements in two torch tensors that also equal a specific value
I'm working in pytorch and trying to count the number of equal elements in 2 torch tensors, that also equal a specific value.
That is, if tensor a=[0,1,2,0,1,2] and tensor b = [0,2,1,0,2,1]
I want it to return:

3 when I check how many element are equal in the a,b and also equals 0. sum(a == b and a == 0 and b == 0) = 2,
0 when I check how many element are equal in the a,b and also equals 1 or 2. sum(a == b and a == 1,2 and b == 1,2) = 0.

Thanks!

A straight forward approach would be:
torch.sum((a==b) * (a==val))

if val is the value you look for.
