[Numpy-discussion] Axis Iterator?
wbaxter at gmail.com
Thu Sep 14 19:53:00 CDT 2006
Iteration over axis 0 is built-in, so you can already do
(vectorFunc(row) for row in array)
And you can use transpose() to make it so the axis you want to iterate
over is axis 0.
(vectorFunc(col) for col in array.transpose(1,0))
Or just use the .T attribute
(vectorFunc(col) for col in array.T)
So it seems kind of a toss-up whether it's worth adding a specific API
to do that. The implementation would probably just return the
transpose with the given axis in the zero slot. Something like:
def axisiter(arr, i):
ax = [i] + range(arr.ndim)
On 9/15/06, Brendan Simons <brendansimons at yahoo.ca> 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.
More information about the Numpy-discussion