From: Alan G I. <ai...@am...> - 2006-06-20 07:08:01
|
I think the distance matrix version below is about as good=20 as it gets with these basic strategies. fwiw, Alan Isaac def dist(A,B): rowsA, rowsB =3D A.shape[0], B.shape[0] distanceAB =3D empty( [rowsA,rowsB] , dtype=3Dfloat) if rowsA <=3D rowsB: temp =3D empty_like(B) for i in range(rowsA): #store A[i]-B in temp subtract( A[i], B, temp ) temp *=3D temp sqrt( temp.sum(axis=3D1), distanceAB[i,:]) else: temp =3D empty_like(A) for j in range(rowsB): #store A-B[j] in temp temp =3D subtract( A, B[j], temp ) temp *=3D temp sqrt( temp.sum(axis=3D1), distanceAB[:,j]) return distanceAB |