@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 math). Let me know if you find any problems.

def ewma(a, d,а int axis = -1):

ааа out = np.empty(a.shape, dtype)
ааа
ааа cdef np.flatiter ita, ito
ааа
ааа ita = np.PyArray_IterAllButAxis(a,аа &axis)
ааа ito = np.PyArray_IterAllButAxis(out, &axis)
ааа
ааа cdef int i
ааа cdef int axis_length = a.shape[axis]
ааа cdef int a_axis_stride = a.strides[axis]/a.itemsize
ааа cdef int o_axis_stride = out.strides[axis]/out.itemsize
ааа
ааа cdef double avg = 0.0
ааа cdef double weight = 1.0 - np.exp(-d)
ааа
ааа
ааа while np.PyArray_ITER_NOTDONE(ita):
ааа ааа
ааа ааа avg = 0.0
ааа ааа for i in range(axis_length):
ааа ааа ааа
ааа ааа ааа avg += (<dtype_t*>np.PyArray_ITER_DATA (ita))[i * a_axis_stride ] * weight + avg * (1 - weight)
ааа ааа ааа (<dtype_t*>np.PyArray_ITER_DATA (ito))[i * o_axis_stride ] = avg
ааа ааа ааа ааа
ааа ааа np.PyArray_ITER_NEXT(ita)
ааа ааа np.PyArray_ITER_NEXT(ito)
ааа ааа
ааа return outааа

On Tue, Nov 30, 2010 at 9:46 PM, Felix Schlesinger wrote:
> > 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. OK, time to upgrade.

Oh wow, does that mean that http://trac.cython.org/cython_trac/ticket/177
is fixed? I couldn't find anything in the release notes about that,
but it would be great news. Does the cdef function acquire and hold
the buffer?

Felix

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion