Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Bill Baxter
Oops. Looks like I forgot to attach the test program that generated that output so you can tell what dist2g actually does. Funny thing is -- despite being written in C, hypot doesn't actually win any of the test cases for which it's applicable. --bb On 4/17/07, Bill Baxter <[EMAIL PROTECTED]> w

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Robert Kern
Christopher Barker wrote: > Matthieu Brucher wrote: >> you can probably use numpy.hypot(v-y) to speed this up more... >> >> Tried it today, hypot takes two arguments :( >> Is there a function that does the square root of the sum of squares ? > > then maybe you want: > > numpy.hypot(v-y,v-y),

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Christopher Barker
Matthieu Brucher wrote: > you can probably use numpy.hypot(v-y) to speed this up more... > > > Tried it today, hypot takes two arguments :( > Is there a function that does the square root of the sum of squares ? then maybe you want: numpy.hypot(v-y,v-y), though you should probably make a te

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Markus Rosenstihl
Or f = sqrt(dot(x,x)) Am 17.04.2007 um 16:12 schrieb Sturla Molden: f = lambda x : sqrt(sum(x**2)) PGP.sig Description: Signierter Teil der Nachricht ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/li

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Sturla Molden
On 4/17/2007 3:57 PM, Matthieu Brucher wrote: > Is there a function that does the square root of the sum of squares ? hm ... f = lambda x : sqrt(sum(x**2)) S.M. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/m

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-17 Thread Matthieu Brucher
you can probably use numpy.hypot(v-y) to speed this up more... Tried it today, hypot takes two arguments :( Is there a function that does the square root of the sum of squares ? Matthieu ___ Numpy-discussion mailing list Numpy-discussion@scipy.org h

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-16 Thread Bill Baxter
Here's a bunch of dist matrix implementations and their timings. The upshot is that for most purposes this seems to be the best or at least not too far off (basically the cookbook solution Kier posted) def dist2hd(x,y): """Generate a 'coordinate' of the solution at a time""" d = npy.zeros((

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-16 Thread Keir Mierle
On 4/13/07, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > On 4/13/07, Bill Baxter <[EMAIL PROTECTED]> wrote: > > I think someone posted some timings about this before but I don't recall. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498246 [snip] > I'm going to go out on a limb and cont

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-16 Thread Christopher Barker
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 thi

Re: [Numpy-discussion] Fastest distance matrix calc

2007-04-13 Thread Timothy Hochberg
On 4/13/07, Bill Baxter <[EMAIL PROTECTED]> wrote: I think someone posted some timings about this before but I don't recall. The task is to compute the matrix D from two sets of vectors x (M,d) and y (N,d). The output should be D where D[i,j] is norm(x[i]-y[j]) The Matlab NetLab toolkit uses

[Numpy-discussion] Fastest distance matrix calc

2007-04-13 Thread Bill Baxter
I think someone posted some timings about this before but I don't recall. The task is to compute the matrix D from two sets of vectors x (M,d) and y (N,d). The output should be D where D[i,j] is norm(x[i]-y[j]) The Matlab NetLab toolkit uses something like this to compute it: d2 = (x*x).sum