Re: [Numpy-discussion] A faster median (Wirth's method)

2010-12-01 Thread John Salvatier
@Keith Goodman I think I figured it out. I believe something like the following will do what you want, iterating across one axis specially, so it can apply a median function along an axis. This code in particular is for calculating a moving average and seems to work (though I haven't checked my ma

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread Felix Schlesinger
> > import numpy as np > > cimport numpy as cnp > > > cdef cnp.float64_t namean(cnp.ndarray[cnp.float64_t, ndim=1] a): > >return np.nanmean(a) # just a placeholder > > > is not allowed? It works for me. Is it a cython version thing? > > (I've got 0.13), > > Oh, that's nice! I'm using 0.11.2.

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread John Salvatier
I think last time I looked into how to apply a function along an axis I thought that the PyArray_IterAllButAxis would not work for that task ( http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_IterAllButAxis), but I think perhaps I misunderstood it. I'm looking into how to use it.

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread Keith Goodman
On Tue, Nov 30, 2010 at 11:58 AM, Matthew Brett wrote: > Hi, > > On Tue, Nov 30, 2010 at 11:35 AM, Keith Goodman wrote: >> On Tue, Nov 30, 2010 at 11:25 AM, John Salvatier >> wrote: >>> I am very interested in this result. I have wanted to know how to do an >> >> My first thought was to write th

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread Matthew Brett
Hi, On Tue, Nov 30, 2010 at 11:35 AM, Keith Goodman wrote: > On Tue, Nov 30, 2010 at 11:25 AM, John Salvatier > wrote: >> I am very interested in this result. I have wanted to know how to do an > > My first thought was to write the reducing function like this > > cdef np.float64_t namean(np.ndar

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread Keith Goodman
On Tue, Nov 30, 2010 at 11:25 AM, John Salvatier wrote: > I am very interested in this result. I have wanted to know how to do an My first thought was to write the reducing function like this cdef np.float64_t namean(np.ndarray[np.float64_t, ndim=1] a): but cython doesn't allow np.ndarray in a

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread John Salvatier
I am very interested in this result. I have wanted to know how to do an apply_along_axis function for a while now. On Tue, Nov 30, 2010 at 11:21 AM, Keith Goodman wrote: > On Tue, Sep 1, 2009 at 2:37 PM, Sturla Molden wrote: > > Dag Sverre Seljebotn skrev: > >> > >> Nitpick: This will fail on l

Re: [Numpy-discussion] A faster median (Wirth's method)

2010-11-30 Thread Keith Goodman
On Tue, Sep 1, 2009 at 2:37 PM, Sturla Molden wrote: > Dag Sverre Seljebotn skrev: >> >> Nitpick: This will fail on large arrays. I guess numpy.npy_intp is the >> right type to use in this case? >> > By the way, here is a more polished version, does it look ok? > > http://projects.scipy.org/numpy/

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-03 Thread Charles R Harris
On Thu, Sep 3, 2009 at 12:14 AM, Sturla Molden wrote: > Chad Netzer skrev: > > That's right, Robert. Basically, I meant doing a median on a square > > (or rectangle) "view" of an array, without first having to ravel(), > > thus generally saving a copy. But actually, since my selection based > >

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Sturla Molden
Chad Netzer skrev: > That's right, Robert. Basically, I meant doing a median on a square > (or rectangle) "view" of an array, without first having to ravel(), > thus generally saving a copy. But actually, since my selection based > median overwrites the source array, it may not save a copy anyway.

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Jon Wright
Chad Netzer wrote: > But Charles Harris's earlier suggestion of some hard coded medians for > common filter template sizes (ie 3x3, 5x5, etc.) may be a nice > addition to scipy, especially if it can be generalized somewhat to > other filters. > For 2D images try looking into PIL : ImageFilter.M

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Sturla Molden
Robert Kern skrev: > When he is talking about 2D, I believe he is referring to median > filtering rather than computing the median along an axis. I.e., > replacing each pixel with the median of a specified neighborhood > around the pixel. > > That's not something numpy's median function should b

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Chad Netzer
On Wed, Sep 2, 2009 at 10:28 PM, Robert Kern wrote: > When he is talking about 2D, I believe he is referring to median > filtering rather than computing the median along an axis. I.e., > replacing each pixel with the median of a specified neighborhood > around the pixel. That's right, Robert. Ba

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Robert Kern
On Thu, Sep 3, 2009 at 00:09, Sturla Molden wrote: > Chad Netzer skrev: >> I'd also like to, if possible, have a specialized 2D version, since >> image media filtering is one of my interests, and the C version works >> on 1D (raveled) arrays only. > I agree. NumPy (or SciPy) could have a select mo

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Sturla Molden
Chad Netzer skrev: > By the way, as far as I can tell, the above algorithm is exactly the > same idea as a non-recursive Hoare (ie. quicksort) selection: Do the > partition, then only proceed to the sub-partition that must contain > the nth element.My version is a bit more general, allowing >

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Charles R Harris
On Wed, Sep 2, 2009 at 1:25 PM, Chad Netzer wrote: > On Mon, Aug 31, 2009 at 9:06 PM, Sturla Molden wrote: > > > > We recently has a discussion regarding an optimization of NumPy's median > > to average O(n) complexity. After some searching, I found out there is a > > selection algorithm competit

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Chad Netzer
On Mon, Aug 31, 2009 at 9:06 PM, Sturla Molden wrote: > > We recently has a discussion regarding an optimization of NumPy's median > to average O(n) complexity. After some searching, I found out there is a > selection algorithm competitive in speed with Hoare's quick select. It > has the advantage

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Robert Bradshaw
On Wed, 2 Sep 2009, Dag Sverre Seljebotn wrote: > Sturla Molden wrote: >> Dag Sverre Seljebotn skrev: >> >>> Nitpick: This will fail on large arrays. I guess numpy.npy_intp is the >>> right type to use in this case? >>> >>> >> By the way, here is a more polished version, does it look ok? >> >> htt

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Sturla Molden
Citi, Luca skrev: > Hello Sturla, > In "_median" how can you, if n==2, use s[] if s is not defined? > What if n==1? > That was a typo. > Also, I think when returning an empty array, it should be of > the same type you would get in the other cases. Currently median returns numpy.nan for empty

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Sturla Molden
Dag Sverre Seljebotn skrev: > a) Is the cast to numpy.npy_intp really needed? I'm pretty sure shape is > > defined as numpy.npy_intp*. I don't know Cython internals in detail but you do, I so take your word for it. I thought shape was a tuple of Python ints. > b) If you want higher perform

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Dag Sverre Seljebotn
Sturla Molden wrote: > Dag Sverre Seljebotn skrev: > >> Nitpick: This will fail on large arrays. I guess numpy.npy_intp is the >> right type to use in this case? >> >> > By the way, here is a more polished version, does it look ok? > > http://projects.scipy.org/numpy/attachment/ticket/1

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-02 Thread Citi, Luca
Hello Sturla, I had a quick look at your code. Looks fine. A few notes... In "select" you should replace numpy with np. In "_median" how can you, if n==2, use s[] if s is not defined? What if n==1? Also, I think when returning an empty array, it should be of the same type you would get in the ot

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-01 Thread Sturla Molden
Sturla Molden skrev: > > http://projects.scipy.org/numpy/attachment/ticket/1213/generate_qselect.py > http://projects.scipy.org/numpy/attachment/ticket/1213/quickselect.pyx My suggestion for a new median function is here: http://projects.scipy.org/numpy/attachment/ticket/1213/median.py The quickse

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-01 Thread Sturla Molden
Sturla Molden skrev: > > By the way, here is a more polished version, does it look ok? No it doesn't... Got to keep the GIL for the general case (sorting object arrays). Fixing that. SM ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-01 Thread Sturla Molden
Dag Sverre Seljebotn skrev: > > Nitpick: This will fail on large arrays. I guess numpy.npy_intp is the > right type to use in this case? > By the way, here is a more polished version, does it look ok? http://projects.scipy.org/numpy/attachment/ticket/1213/generate_qselect.py http://projects.sc

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-01 Thread Sturla Molden
Dag Sverre Seljebotn skrev: > Nitpick: This will fail on large arrays. I guess numpy.npy_intp is the > right type to use in this case? > > Yup. You are right. Thanks. Sturla ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mai

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-09-01 Thread Dag Sverre Seljebotn
Sturla Molden wrote: > We recently has a discussion regarding an optimization of NumPy's median > to average O(n) complexity. After some searching, I found out there is a > selection algorithm competitive in speed with Hoare's quick select. It > has the advantage of being a lot simpler to implem

Re: [Numpy-discussion] A faster median (Wirth's method)

2009-08-31 Thread Sturla Molden
Sturla Molden skrev: > We recently has a discussion regarding an optimization of NumPy's median > to average O(n) complexity. After some searching, I found out there is a > selection algorithm competitive in speed with Hoare's quick select. > > Reference: > http://ndevilla.free.fr/median/median.p

[Numpy-discussion] A faster median (Wirth's method)

2009-08-31 Thread Sturla Molden
We recently has a discussion regarding an optimization of NumPy's median to average O(n) complexity. After some searching, I found out there is a selection algorithm competitive in speed with Hoare's quick select. It has the advantage of being a lot simpler to implement. In plain Python: impor