# [Numpy-discussion] Giving numpy the ability to multi-iterate excluding an axis

Mark Wiebe mwwiebe@gmail....
Wed Dec 22 10:54:11 CST 2010

```On Wed, Dec 22, 2010 at 12:44 AM, John Salvatier
<jsalvati@u.washington.edu>wrote:

> This now makes sense to me, and I think it should work :D. This is all very
> cool. This is going to do big things for cython and numpy.
>
> Some hopefully constructive criticism:
>
> When first reading through the API description, the way oa_ndim and oa_axes
> work is not clear. I think your description would be clearer if you explain
> what oa_ndim means (I gather something like "the number of axes over which
> you wish to iterate"), currently it just says "These parameters let you
> control in detail how the axes of the operand arrays get matched together
> and iterated."
>

Thanks, I've tried to clean up the description a bit.

> It's also not totally clear to me how offsetting works. What are the
> offsets measured from? It seems like they are measured from another
> iterator, but I'm not sure and I don't see how it gets that information.
>

I added an example to the NEP to try to make it more clear, here's what I
wrote:

To help understand how the offsets work, here is a simple nested iteration
example. Let's say our array a has shape (2, 3, 4), and strides (48, 16, 4).
The data pointer for element (i, j, k) is at address PyArray_BYTES(a) + 48*i
+ 16*j + 4*k. Now consider two iterators with custom op_axes (0,1) and (2,).
The first one will produce addresses like PyArray_BYTES(a) + 48*i + 16*j,
and the second one will produce addresses likePyArray_BYTES(a) + 4*k. Simply
make the outer iterator produce offsets, in which case it will produce the
values 48*i + 16*j, and its sum with the other iterator's pointer gives the
correct data address. It's important to note that this will not work if any
of the iterators share an axis. The iterator cannot check this, so your code
must handle it.

Additionally, taking a look at the ndarray strides documentation might help:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.strides.html

Cheers,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101222/54afd171/attachment.html
```