What would be the output value, if the first position contains a zero for a and b?
This code should work:
a = torch.tensor([1, 0, 0, 0, 1, 0])
b = torch.tensor([0, 0, 1, 0, 0, 0])

res = ((a==1) & (b==0)).long()
idx = ((a==0) & (b==0)).nonzero()
res[idx] = res[idx-1]

print(res)
> tensor([1, 1, 0, 0, 1, 1])

Although, is should write a 1 at the last position, if the first entry is a double 0.