我有两个大小为trainv = 60000X784和testv = 10000X784的矩阵。如何有效地计算testv和trainv中每个向量之间的欧氏距离?以这种方式完成它需要相当长的时间:
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