Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread LB
Thank you Gael, I think this could work for my case. It will be a bit tricky, since calc_0d is already a closure in which I've defined a function : the parameters x and y are to main parameters of an ODE. So calc_0d define a function, integrate it sing scipy.integrate.odeint and returns some chara

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Charles R Harris
On Jan 30, 2008 10:18 AM, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > > > On Jan 30, 2008 10:10 AM, Charles R Harris <[EMAIL PROTECTED]> > wrote: > > [SNIP] > > > > > > IIRC, the way to do closures in Python is something like > > > > In [5]: def factory(x) : > >...: def f() : > >...:

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Charles R Harris
On Jan 30, 2008 10:10 AM, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On Jan 30, 2008 2:22 AM, Gael Varoquaux <[EMAIL PROTECTED]> > wrote: > > > On Wed, Jan 30, 2008 at 12:49:44AM -0800, LB wrote: > > > My problem is that the complexe calculations made in calc_0d use some > > > parameters, w

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Timothy Hochberg
On Jan 30, 2008 10:10 AM, Charles R Harris <[EMAIL PROTECTED]> wrote: [SNIP] > > IIRC, the way to do closures in Python is something like > > In [5]: def factory(x) : >...: def f() : >...: print x >...: f.x = x >...: return f >...: > > In [6]: f = factory(

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Charles R Harris
On Jan 30, 2008 2:22 AM, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > On Wed, Jan 30, 2008 at 12:49:44AM -0800, LB wrote: > > My problem is that the complexe calculations made in calc_0d use some > > parameters, which are currently defined at the head of my python file. > > This is not very nice an

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Anne Archibald
On 30/01/2008, Scott Ransom <[EMAIL PROTECTED]> wrote: > That works fine with arrays, scalars, or array/scalar mixes in the > calling. I do understand that more complicated functions might > require vectorize(), however, I wonder if sometimes it is used > when it doesn't need to be? It certainly

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Scott Ransom
On a side note, given that I've seen quite a few posts about vectorize() over the past several months... I've written hundreds or thousands of functions that are intended to work with numeric/numpy arrays and/or scalars and I've _never_ (not once!) found a need for the vectorize function. Python'

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread Gael Varoquaux
On Wed, Jan 30, 2008 at 12:49:44AM -0800, LB wrote: > My problem is that the complexe calculations made in calc_0d use some > parameters, which are currently defined at the head of my python file. > This is not very nice and I can't define a module containing theses > two functions and call them wi

Re: [Numpy-discussion] Vectorizing a function

2008-01-30 Thread YW
Try use a closure. On Jan 30, 12:49 am, LB <[EMAIL PROTECTED]> wrote: >    Hi, > > I've got some questions on the numpy.vectorize  function. > Currently, i'm doing this kind of work : > > [ code] > def calc_0d(x, y): >     """ make complexe calculation using two scalars x and y """ >     [ ... ] >

[Numpy-discussion] Vectorizing a function

2008-01-30 Thread LB
Hi, I've got some questions on the numpy.vectorize function. Currently, i'm doing this kind of work : [ code] def calc_0d(x, y): """ make complexe calculation using two scalars x and y """ [ ... ] return res1, res2, res 3 # vectorize the function calc = vectorize(calc_0d) res1,