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

2015-10-07 Thread Matti Picus

  
  
 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?
  
  Matti

  

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


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

2015-10-07 Thread Mark Wiebe
On Wed, Oct 7, 2015 at 12:59 PM, Matti Picus  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@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion