I have a symmetric tensor of size
[B, N, N, C]. I would like to eliminate the diagonal elements. I was wondering what is the most efficient way to do this?
idx1 = torch.triu_indices(N, N, 0) idx2 = torch.triu_indices(N, N, 1)
Then turn them into lists, subtract to get diagonal indices. Then use them to subtract diagonal term from the original tensor. But I’m wondering
- Would turning indices into list break backprop?
- Also, I’m not sure if this is the most efficient way to do this.