Torch: Broadcasting to different shape based on a condition

Viewed 31

I have a tensor

labels= torch.tensor([[1,1],[0,1],[0,0]])

This is of shape 3x2 (NXC) I would like a tensor of shape NXN i.e, 3x3 from this tensor i.e,

     Output = tensor([[1., 1., 0.],
                      [1., 1., 1.],
                      [0., 1., 1.]])

Condition is if any value inside the tensor is 1 when matching element wise, it evaluates to 1. For e.g [1,1],[0,1] = 1 and [0,1],[1,0] = 0

I would like a broadcast able answer since working with 2 for loops is increasing my time complexity if N is scaled up to 32,64.

0 Answers
Related