0

I have two matrices of size trainv = 60000X784 and testv = 10000X784. How is it possible to efficiently compute the Euclidean distance between each vector in testv and trainv? It takes quite a long time to do it in this way:

 for j = 1:60000
    for i = 1:10000
        d(i,j) = norm((trainv(i,:)-testv(j,:)),2);
        %d(i,j) = bsxfun(@plus,dot(trainv(i,:),trainv(i,:),2),dot(testv(j,:),testv(j,:),2)')-2*(trainv(i,:)*testv(j,:)');
    end

end
KianStar
  • 177
  • 1
  • 9
  • Also, look [here](http://stackoverflow.com/a/26994722/3293881) for explanation and vectorized variations to the proposed solution of the dup-linked question. – Divakar Dec 21 '15 at 12:10
  • Thank you, I tried to employ his next last method, namely bsxfun. (As you see in my code as comment) but it didn't help. But how to write helpA and helpB (the first method) for my case? – KianStar Dec 21 '15 at 12:23

0 Answers0