[Numpy-discussion] Axis Iterator?

Travis Oliphant oliphant at ee.byu.edu
Thu Sep 14 19:31:43 CDT 2006

Brendan Simons wrote:

>Hi all,
>Just wondering if there was an arbitrary axis iterator in numpy, or  
>if not, if there's demand for one.  What I'm looking for is something  
>which would allow me to do  something like (vectorFunc(column) for  
>column in array.axisIter(1) )  without a bunch of for loops and slicing.

Hmm... I can't think of something directly in Python, but it would be 
pretty easy to add.  You could probably also do something clever by 
creating your own ufunc with frompyfunc and object arrays. 

In C, this would be easy.  In the C-API there is a function 
PyArray_IterAllButAxis which provides an iterator that iterates over all 
axes but one.   Then, you would call the vectorFunc for each element in 
the loop.

The ufuncs use this functionality to call the underlying 1-d loops. 


More information about the Numpy-discussion mailing list