How to do the same thing when values are repeated on a dimension?
a=tensor([[1296, 1295, 1292,    4, 1311,    4, 1293,    2],
        [1297, 1295, 1292, 1404, 1293,    4, 1293,    2]]

a should become:
a = tensor([[3, 2, 1292,    4, 5,    4, 1,    2],
        [3, 2, 1292, 4, 1,    4, 1,    2]]