Mask only diagonal factor

I have an tensor, say, 128 * 128, like

tensor([[3851, 3971,  535,  ..., 3803, 3963,  485],
        [1437, 3264, 3824,  ..., 1611, 3128,  649],
        [3947, 3634,  511,  ..., 1114, 3478, 1490],
        ...,
        [3174, 1381,   -1,  ..., 3436,   -1, 1213],
        [2325, 2251,   -1,  ...,   70, 3354, 3038],
        [2031, 3100, 2623,  ..., 3309, 1328,  785]])

and filter this tensor.
What I want to get is

tensor([[-1, 3971,  535,  ..., 3803, 3963,  485],
        [1437, -1, 3824,  ..., 1611, 3128,  649],
        [3947, 3634,  -1,  ..., 1114, 3478, 1490],
        ...,
        [3174, 1381,   -1,  ..., -1,   -1, 1213],
        [2325, 2251,   -1,  ...,   70, -1, 3038],
        [2031, 3100, 2623,  ..., 3309, 1328,  -1]])

I’m trying to find permutation by which I can get this, but can’t.
If you’d know how to do this, I’d appreciate it much.
Thanks.

do you mean something like this,

x[x == x.diag()] = -1

Thanks, I’ll try that.