Re: [Numpy-discussion] finding minimum distance using arrays

2008-04-22 Thread Nadav Horesh
from numpy import * def distance(v1,v2): return sqrt(((v2-v1)**2).sum()) def findmatch(wts,inputwt): dist2 = ((wts-inputwt)**2).sum(axis=1) idx = argmin(dist2) return idx, sqrt(dist2[idx]) Nadav -הודעה מקורית- מאת: [EMAIL PROTECTED] בשם wilson נשלח: ד 23-אפריל-08 08:00 אל:

Re: [Numpy-discussion] finding minimum distance using arrays

2008-04-22 Thread Robert Kern
On Wed, Apr 23, 2008 at 1:00 AM, wilson <[EMAIL PROTECTED]> wrote: > hi > i wrote a function to find euclidian distance between two vectors and > applied it to the rows of a 2d array of floats as below > > > from math import sqrt > from numpy import array,sum > > def distance(vec1, vec2): >

[Numpy-discussion] finding minimum distance using arrays

2008-04-22 Thread wilson
hi i wrote a function to find euclidian distance between two vectors and applied it to the rows of a 2d array of floats as below from math import sqrt from numpy import array,sum def distance(vec1, vec2): return sqrt(sum([(x-y)**2 for x,y in zip(vec1, vec2)])) def findmatch(wts,inputwt):

Re: [Numpy-discussion] access ndarray in C++

2008-04-22 Thread Robert Kern
On Tue, Apr 22, 2008 at 4:38 PM, Thomas Hrabe <[EMAIL PROTECTED]> wrote: > > Hi all! > > I am currently developing a python module in C/C++ which is supposed to > access nd arrays as defined by the following command in python > > a = numpy.array([1,1,1]) > > I want to access the array the follow

Re: [Numpy-discussion] access ndarray in C++

2008-04-22 Thread Joris De Ridder
On http://www.scipy.org/JorisDeRidder I've just put an example how I passed multidimensional Numpy arrays to C++ using ctypes. Perhaps it's helpful for your application. I didn't put it in the cookbook yet, because I would first like to test it a bit more. Up to now I didn't experience an

Re: [Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread Charles R Harris
On Tue, Apr 22, 2008 at 5:51 PM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Tue, Apr 22, 2008 at 4:00 PM, Travis E. Oliphant < > [EMAIL PROTECTED]> wrote: > > > Stéfan van der Walt wrote: > > > 2008/4/22 lorenzo bolla <[EMAIL PROTECTED]>: > > > > > >> I noticed a change in the behaviour

Re: [Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread Charles R Harris
On Tue, Apr 22, 2008 at 4:00 PM, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: > Stéfan van der Walt wrote: > > 2008/4/22 lorenzo bolla <[EMAIL PROTECTED]>: > > > >> I noticed a change in the behaviour of numpy.asfarray between numpy > version > >> 1.0.5 and 1.1.0: > >> > >> 1.0.5 > >> > >> >

Re: [Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread Travis E. Oliphant
Stéfan van der Walt wrote: > 2008/4/22 lorenzo bolla <[EMAIL PROTECTED]>: > >> I noticed a change in the behaviour of numpy.asfarray between numpy version >> 1.0.5 and 1.1.0: >> >> 1.0.5 >> >> >> In [3]: numpy.asfarray(None) >> Out[3]: array(nan) >> In [4]: numpy.__version__ >> Out[4]: '1.0

[Numpy-discussion] access ndarray in C++

2008-04-22 Thread Thomas Hrabe
Hi all! I am currently developing a python module in C/C++ which is supposed to access nd arrays as defined by the following command in python a = numpy.array([1,1,1]) I want to access the array the following way and use the nd array data for further processing in C. mymod.doSthg(a) The exam

Re: [Numpy-discussion] Fromfunction generalization

2008-04-22 Thread Alan G Isaac
On Tue, 22 Apr 2008, lorenzo bolla apparently wrote: > M=fromfunction(lambda i,j:f(i,j,5),(1000,1000)) > P=fromfunction(lambda i,j:f(i,j,7),(1000,1000)) Maybe partial function application is nicer: http://docs.python.org/whatsnew/pep-309.html> fwiw, Alan Isaac __

Re: [Numpy-discussion] Fromfunction generalization

2008-04-22 Thread Gnata Xavier
Well done in python :) Is there a "numpy way" to do that (only asking for the fun because this solution is nice)? Xavier, who do like lamba functions :) > what about using lambda functions? > > M=fromfunction(lambda i,j:f(i,j,5),(1000,1000)) > P=fromfunction(lambda i,j:f(i,j,7),(1000,1000)) > > L

[Numpy-discussion] Adding nested loops to template processor.

2008-04-22 Thread Charles R Harris
Hi All, I want to use nested loops in our c template processor. The least intrusive way I see to do this is to change the repeat header slightly, i.e. /**begin repeat #var1= a, b, c# #var2= d, e, f# #nest=1# #var3= w, x# #var4= y, z# */ Where "nest" becomes a keyword. The variables then take va

Re: [Numpy-discussion] Fromfunction generalization

2008-04-22 Thread lorenzo bolla
what about using lambda functions? M=fromfunction(lambda i,j:f(i,j,5),(1000,1000)) P=fromfunction(lambda i,j:f(i,j,7),(1000,1000)) L. On Tue, Apr 22, 2008 at 8:42 PM, Gnata Xavier <[EMAIL PROTECTED]> wrote: > Hi, > > fromfunction is fine but I have like to be able to create 2Darrays using > a f

[Numpy-discussion] Fromfunction generalization

2008-04-22 Thread Gnata Xavier
Hi, fromfunction is fine but I have like to be able to create 2Darrays using a function of i,j but also of one (or more) parameters. Something like that : def f(i,j,a): return (i+j)*a #replace that by another non trivial computation M=fromfunction(f( hum well something like i,j,a),(1000,100

Re: [Numpy-discussion] [matplotlib-devel] Numpy 1.1.0 and matplotlib 0.90.1

2008-04-22 Thread Eric Firing
This is inherent; mpl 0.90.1 is permanently incompatible with numpy 1.1, short of each user making the change suggested below. The earliest mpl that should work with numpy 1.1 is 0.91.2. The change in masked array module is a major reason why numpy is getting a version bump to 1.1.0 instead of

Re: [Numpy-discussion] Numpy 1.1.0 and matplotlib 0.90.1

2008-04-22 Thread Jarrod Millman
On Tue, Apr 22, 2008 at 4:45 AM, lorenzo bolla <[EMAIL PROTECTED]> wrote: > the latest svn numpy version 1.1.0.dev5061 does not work with matplotlib > 0.90.1 (version shipped with enthought distribution), ... I believe this is fixed with 0.91.2. Please see their release notes: http://matplotlib.s

Re: [Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread Stéfan van der Walt
2008/4/22 lorenzo bolla <[EMAIL PROTECTED]>: > I noticed a change in the behaviour of numpy.asfarray between numpy version > 1.0.5 and 1.1.0: > > 1.0.5 > > > In [3]: numpy.asfarray(None) > Out[3]: array(nan) > In [4]: numpy.__version__ > Out[4]: '1.0.5.dev4455' > > 1.1.0 > > > In [16]: nu

[Numpy-discussion] different behaviour in asfarray(None)

2008-04-22 Thread lorenzo bolla
I noticed a change in the behaviour of numpy.asfarray between numpy version 1.0.5 and 1.1.0: 1.0.5 In [3]: numpy.asfarray(None) Out[3]: array(nan) In [4]: numpy.__version__ Out[4]: '1.0.5.dev4455' 1.1.0 In [16]: numpy.asfarray(None)

Re: [Numpy-discussion] Code generator bug and fix?

2008-04-22 Thread Charles R Harris
On Tue, Apr 22, 2008 at 8:15 AM, Travis E. Oliphant <[EMAIL PROTECTED]> wrote: > Charles R Harris wrote: > > > > I note that other logical operators, <, ==, do in fact return booleans > > when operating on objects. So another fix is to write special case > > loops for logical_{not, or, and, xor} t

Re: [Numpy-discussion] Numpy 1.1.0 and matplotlib 0.90.1

2008-04-22 Thread Michael Droettboom
I will forward it to the matplotlib-devel mailing list on your behalf. Cheers, Mike lorenzo bolla wrote: > Hello, > > the latest svn numpy version 1.1.0.dev5061 does not work with > matplotlib 0.90.1 (version shipped with enthought distribution), > unless a change in > Python25/Lib/site-packag

Re: [Numpy-discussion] Code generator bug and fix?

2008-04-22 Thread Travis E. Oliphant
Charles R Harris wrote: > > I note that other logical operators, <, ==, do in fact return booleans > when operating on objects. So another fix is to write special case > loops for logical_{not, or, and, xor} that do the same. Perhaps a > ticket for an enhancement should be opened. There should a

[Numpy-discussion] Numpy 1.1.0 and matplotlib 0.90.1

2008-04-22 Thread lorenzo bolla
Hello, the latest svn numpy version 1.1.0.dev5061 does not work with matplotlib 0.90.1 (version shipped with enthought distribution), unless a change in Python25/Lib/site-packages/matplotlib-0.90.1.0003-py2.5-win32.egg/matplotlib/numerix/ma/__init__.py is done: $ diff __init__.py.orig __init__.py

[Numpy-discussion] [numscons] 0.6.3 release: building scipy with MS compilers works

2008-04-22 Thread David Cournapeau
Hi, Sorry for announcing one more numscons release in such a short time: this releases can finally handle the last common platform, Visual Studio on win32. Win32 installers and source tarballs can be found on launchpad, as usual: https://code.launchpad.net/numpy.scons.support/0.6/0.6.3 Py

Re: [Numpy-discussion] Summing indices of heterogeneous shapes

2008-04-22 Thread Michael Hoffman
Michael Hoffman wrote: > In the following example I can sum up lists of column indices: > > >>> x = numpy.arange(30) > >>> x.shape = (6, 5) > >>> x > array([[ 0, 1, 2, 3, 4], > [ 5, 6, 7, 8, 9], > [10, 11, 12, 13, 14], > [15, 16, 17, 18, 19], > [20, 21, 2