What is a time-efficient way to find min-distance element of one tensor for each element of another tensor?


How to compute min-distance column of B for each column of A
In the following attempt: for all b_j in B, find argmin(i) norm(a_i,b_j)

a_i = column i of matrix A (M x N)
b_j = column j of matrix B (K x N)

Should return: m \in I^M, len(m) = K


A = torch.rand(20,200)
B = torch.rand(10,200)
torch.norm(A - B.transpose(1,0).unsqueeze(0).repeat(20,1,1),dim=2).argmin()

RuntimeError: The size of tensor a (200) must match the size of tensor b (10) at non-singleton dimension 2