[Numpy-discussion] Proposal of new function: iteraxis()

andrew giessel andrew.giessel@gmail....
Wed Apr 24 16:37:09 CDT 2013


Hello all-

A while back I emailed the list about function for the numpy namespace,
iteraxis(), which allows you to generalize the default iteration behavior
of numpy arrays over any axis.

I've implemented this function more cleanly and the pull request is here:
https://github.com/numpy/numpy/pull/3262, and includes passing tests and
documentation.

This is very simple code, which uses np.rollaxis() to bring the desired
dimension to the front, and then allows you to loop over slices in this
re-structured view of the array.  While little more than an alias, I feel
this is a very useful function because looping over iterators is a core
pattern in python, and makes working with slices of any multidimensional
array very pythonic.  Adding this function makes this more visible for
users, new and old, and I hope members of this list will agree it is worth
adding to the namespace.

Generalizing this to iterate over multiple axes is something that might be
worthwhile, but the specifics of how to implement the axis ordering would
take some thought.  I'm happy to discuss and tackle this if people are
really interested.

Hoping for some nice feedback,

ag


-- 
Andrew Giessel, PhD

Department of Neurobiology, Harvard Medical School
220 Longwood Ave Boston, MA 02115
ph: 617.432.7971 email: andrew_giessel@hms.harvard.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130424/f9022d1b/attachment.html 


More information about the NumPy-Discussion mailing list