[Numpy-discussion] Raveling, reshape order keyword unnecessarily confuses index and memory ordering

Matthew Brett matthew.brett at gmail.com
Thu Apr 4 15:40:58 EDT 2013


On Thu, Apr 4, 2013 at 11:45 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
> Hi,
> On Thu, Apr 4, 2013 at 9:21 AM, Chris Barker - NOAA Federal
> <chris.barker at noaa.gov> wrote:
>> On Wed, Apr 3, 2013 at 6:13 PM, Matthew Brett <matthew.brett at gmail.com> wrote:
>>>> We all agree that 'order' is used with two different and orthogonal
>>>> meanings in numpy.
> Brief thank you for your helpful and thoughtful discussion.
>> well, not entirely orthogonal -- they are the some concept, used in
>> different contexts,
> Here's a further clarification, in the hope that it is helpful:
> Input and output index orderings are orthogonal - I can read the data
> with C index ordering and return an array that is index ordered
> any-old-how.
> F and C are used in the sense of F contiguous and C contiguous - where
> contiguous is not the same concept as index ordering.
> So I think it's hard to say these concepts are not orthogonal, simply
> in the technical sense that order='F" could mean:
> * read my data using F-style index ordering
> * return my data in an array using F-style index ordering
> * (related to above) return my data in F-contiguous memory layout

Sorry this is not well-put and should increase confusion rather than
decrease it.  I'll try again if I may.

What do we mean by 'Fortran' 'order'.

Two things :

* np.array(a, order='F') - Fortran contiguous : the array memory is
contiguous, the strides vector is strictly increasing
* np.ravel(a, order='F') - first-to-last index ordering used to
recover values from the array

They are related in the sense that Fortran contiguous layout in memory
means that returning the elements as stored in memory gives the same
answer as first to last index ordering.  They are different in the
sense that first-to-last index ordering applies to any memory layout -
is orthogonal to memory layout.   In particular 'contiguous' has no
meaning for first-to-last or last-to-first index ordering.

So - to restate in other words - this :

np.reshape(a, (3, 4), order='F')

could reasonably mean one of two orthogonal things

1) Retrieve data from the array using first-to-last indexing, return
any memory layout you like
2) Retrieve data from the array using the default last-to-first index
ordering, and return memory in F-contiguous layout



More information about the NumPy-Discussion mailing list