I have a tensor, lets say like this:
tensor([[2.7183, 0.4005, 2.7183, 0.5236],
[0.4005, 2.7183, 0.4004, 1.3469],
[2.7183, 0.4004, 2.7183, 0.5239],
[0.5236, 1.3469, 0.5239, 2.7183]])
And I want to zero its main diagonal by multiplying it by (1-I), meaning by 1 minus the identity matrix. How can I do this in pytorch?
Result of the example should be:
tensor([[0.0000, 0.4005, 2.7183, 0.5236],
[0.4005, 0.0000, 0.4004, 1.3469],
[2.7183, 0.4004, 0.0000, 0.5239],
[0.5236, 1.3469, 0.5239, 0.0000]])
I'm looking for a general case solution and not specific to the example I gave. Thanks!