[Numpy-discussion] Fastest distance matrix calc

Christopher Barker Chris.Barker@noaa....
Mon Apr 16 16:13:00 CDT 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@noaa.gov


More information about the Numpy-discussion mailing list