[Numpy-discussion] A faster median (Wirth's method)
Wed Sep 2 03:50:03 CDT 2009
I had a quick look at your code.
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 other cases.
You could replace _median with the following.
def _median(x, inplace):
assert(x.ndim == 1)
n = x.shape
if n > 2:
k = n >> 1
s = select(x, k, inplace=inplace)
if n & 1:
elif n == 0:
return np.empty(0, dtype=x.dtype)
elif n == 2:
else: # n == 1
More information about the NumPy-Discussion