I don’t understand how z is created in your example.
Based on x and y, the indices of the different values would be:
(x != y).nonzero()
> tensor([[0, 2],
          [0, 6],
          [1, 2],
          [1, 5]])

However, z  seems to be changed at columns 6 and 7 with the values 2 and 1?
Could you explain how these values were set?