Hi,
Supposing that I have L = [1 1 1 0 0 2 2]
, where each number indicates a different class. Using MATLAB, I can write:
A = zeros(numel(L));
A = bsxfun(@eq,L,L.');
A(~L,~L) = 0;
which gives
A =
1 1 1 0 0 0 0
1 1 1 0 0 0 0
1 1 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 1 1
0 0 0 0 0 1 1
Please, how can I do this in pytorch and with no loops?
Thanks
This question is similar to this stackoverflow question