[Numpy-discussion] Fastest distance matrix calc

Christopher Barker Chris.Barker at noaa.gov
Mon Apr 16 17:13:00 EDT 2007


Timothy Hochberg wrote:
> results = empty([M, N], float)
> # You could be fancy and swap axes depending on which array is larger, but
> # I'll leave that for someone else
> for i, v in enumerate(x):
>     results[i] = sqrt(sum((v-y)**2, axis=-1))


you can probably use numpy.hypot(v-y) to speed this up more...


-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list