[Numpy-discussion] Axis Iterator?
Tim Hochberg
tim.hochberg at ieee.org
Thu Sep 14 21:20:08 EDT 2006
Bill Baxter wrote:
> 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)
> del ax[i+1]
> return arr.transpose(ax)
>
> --bb
>
Isn't swapaxis appropriate for this? In other words:
for x in arr.swapaxis(0, i):
#...
should be more or less the same as:
for x in axister(arr, i):
#....
and it already exists. I'm in a hurry, so I haven't checked the details
here, but the basic idea seems sound.
-tim
> 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.
>>
>> Thoughts?
>> Brendan
>>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>
>
More information about the NumPy-Discussion
mailing list