Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Karol Langner
On Friday 05 of January 2007 19:29, Matt Knox wrote: > > On Friday 05 of January 2007 17:42, Matt Knox wrote: > > > - > > > Example 1 - exponential moving average: > > > > > > # naive brute force method... > > > def expmave(x, k): > > > result = numpy

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Matt Knox
> Are you sure about this? I ran this case using timeit, and the first one > was 5 times or so *faster* than the second case. I just dug around and > frompyfunc is acutally implemented in C, although it has to call back > into python to execute the function being vectorized. Can you try using >

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Tim Hochberg
Matt Knox wrote: >>> You might want to look at frompyfunc: >>> >>> def expmave2(x, k): >>> def expmave_sub(a, b): >>> return a + k * (b - a) >>> return np.frompyfunc(expmave_sub, 2, 1).accumulate(x) >>> >>> >>> It's amazing wha

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Matt Knox
> >> > > You might want to look at frompyfunc: > > > > def expmave2(x, k): > > def expmave_sub(a, b): > > return a + k * (b - a) > > return np.frompyfunc(expmave_sub, 2, 1).accumulate(x) > > > > > > It's amazing what you find when you dig around.

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Travis Oliphant
Tim Hochberg wrote: >A. M. Archibald wrote: > > >[SNIP] > > >>Really it would be nice if what vectorize() returned were effectively >>a ufunc, supporting all the various operations we might want from a >>ufunc (albeit inefficiently). This should not be difficult, but I am >>not up to writing it

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Tim Hochberg
Tim Hochberg wrote: > A. M. Archibald wrote: > > > [SNIP] > >> Really it would be nice if what vectorize() returned were effectively >> a ufunc, supporting all the various operations we might want from a >> ufunc (albeit inefficiently). This should not be difficult, but I am >> not up to writing

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Tim Hochberg
A. M. Archibald wrote: [SNIP] > > Really it would be nice if what vectorize() returned were effectively > a ufunc, supporting all the various operations we might want from a > ufunc (albeit inefficiently). This should not be difficult, but I am > not up to writing it this evening. > You might

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread A. M. Archibald
On 05/01/07, Charles R Harris <[EMAIL PROTECTED]> wrote: > On 1/5/07, Tim Hochberg <[EMAIL PROTECTED]> wrote: > > Matt Knox wrote: > > > Basically, I'd like to be able to do accumulate operations with custom > functions. numpy.vectorize does not seem to provide an accumulate method > with the func

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Jeff Whitaker
Matt Knox wrote: > I made a post about this a while ago on the scipy-user mailing list, but I > didn't receive much of a response so I'm just throwing it out there again > (with more detail) in case it got overlooked. > > Basically, I'd like to be able to do accumulate operations with custom > f

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Charles R Harris
On 1/5/07, Tim Hochberg <[EMAIL PROTECTED]> wrote: Matt Knox wrote: > I made a post about this a while ago on the scipy-user mailing list, but I didn't receive much of a response so I'm just throwing it out there again (with more detail) in case it got overlooked. > > Basically, I'd like to be a

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Tim Hochberg
Matt Knox wrote: > I made a post about this a while ago on the scipy-user mailing list, but I > didn't receive much of a response so I'm just throwing it out there again > (with more detail) in case it got overlooked. > > Basically, I'd like to be able to do accumulate operations with custom > f

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Matt Knox
> > On Friday 05 of January 2007 17:42, Matt Knox wrote: > > - > > Example 1 - exponential moving average: > > > > # naive brute force method... > > def expmave(x, k): > > result = numpy.array(x, copy=True) > > for i in range(1, result.size): > >

Re: [Numpy-discussion] custom accumlators

2007-01-05 Thread Karol Langner
On Friday 05 of January 2007 17:42, Matt Knox wrote: > - > Example 1 - exponential moving average: > > # naive brute force method... > def expmave(x, k): > result = numpy.array(x, copy=True) > for i in range(1, result.size): >result[i] = r

[Numpy-discussion] custom accumlators

2007-01-05 Thread Matt Knox
I made a post about this a while ago on the scipy-user mailing list, but I didn't receive much of a response so I'm just throwing it out there again (with more detail) in case it got overlooked. Basically, I'd like to be able to do accumulate operations with custom functions. numpy.vectorize d