[Numpy-discussion] nditer when using operands with mixed C and F order

Mark Wiebe mwwiebe at gmail.com
Wed Oct 7 16:14:39 EDT 2015


On Wed, Oct 7, 2015 at 12:59 PM, Matti Picus <matti.picus at gmail.com> wrote:

> I am trying to understand how nditer(ops, order='K') handles C and F
> order. In the documentation it states
> "‘K’ means as close to the order the array elements appear in memory as
> possible"
> but I seem to be getting inconsistent results (numpy 1.9):
>
>     >>> a = np.array([[1, 2], [3, 4]], order="C")
>     >>> b = np.array([[1, 2], [3, 4]], order="F")
>     >>> [v for v in np.nditer([a], order='K')]
>
>     [array(1), array(2), array(3), array(4)]
>
>     >>> [v for v in np.nditer([b], order='K')]
>     [array(1), array(3), array(2), array(4)]
>     >>> [v for v in np.nditer([a,b], order='K')]
>     [(array(1), array(1)), (array(2), array(2)), (array(3), array(3)),
> (array(4), array(4))]
>
> The result for np.nditer([b], order='K') seems to be wrong. Could someone
> confirm this is an issue or explain what is going on?
>

In this example, elements of a and b are being matched up according to
their array indices, and then the iteration order is chosen according to
the 'K' rule. The array a suggests to go in 'C' order, while the array b
suggests to go in 'F' order. When there's a conflict/ambiguity such as
this, it's resolved in the direction of 'C' order. If it were to go through
a and b in each individual 'K' order, the elements wouldn't be paired
up/broadcast together, which is the whole point of iterating over multiple
arrays via the nditer.

-Mark

>
>
> Matti
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151007/68baa5b9/attachment.html>


More information about the NumPy-Discussion mailing list