1 Dec 06:40 2010

### How can I use PyArray_IterAllButAxis to iterate along an axis

John Salvatier <jsalvatier <at> gmail.com>

2010-12-01 05:40:54 GMT

2010-12-01 05:40:54 GMT

I am trying to make a ufunc like function which takes an axis argument, applying along an axis, using PyArray_IterAllButAxis (http:// docs.scipy.org/doc/numpy/reference/c- api.array.html#PyArray_IterAllButAxis). However, I haven't been able to figure out how I should step along that axis on each iteration. I think I should be able to do something like the following, but I am not sure if it's correct to index into the ITER_DATA like that and/or what stride I should be using. This compiles and runs without error but gives me junk for most of the output array values. 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 L = a.strides[axis] 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):(Continue reading)