[Numpy-discussion] Raveling, reshape order keyword unnecessarily confuses index and memory ordering
Thu Apr 4 15:33:35 CDT 2013
On Thu, Apr 4, 2013 at 4:02 PM, Matthew Brett <firstname.lastname@example.org> wrote:
> On Thu, Apr 4, 2013 at 12:54 PM, <email@example.com> wrote:
>> On Thu, Apr 4, 2013 at 3:40 PM, Matthew Brett <firstname.lastname@example.org> wrote:
>>> On Thu, Apr 4, 2013 at 11:45 AM, Matthew Brett <email@example.com> wrote:
>>>> On Thu, Apr 4, 2013 at 9:21 AM, Chris Barker - NOAA Federal
>>>> <firstname.lastname@example.org> wrote:
>>>>> On Wed, Apr 3, 2013 at 6:13 PM, Matthew Brett <email@example.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
>>>> 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
>> no to interpretation 2)
>> reshape and ravel (in contrast to flatten) just return a view (if possible)
>> (with possible some strange strides)
> 'No' meaning what? That it is not possible that it could mean that?
> Obviously we're not arguing about whether it does mean that, we're
> arguing about whether such an interpretation would make sense.
'No' means: I don't think it makes sense given the current behavior of numpy
with respect to functions that are designed to return views
(and copy memory only if there is no way to make a view)
One objective of functions that create views is *not* to change the underlying
memory. So in most cases, requesting a specific contiguity (memory order)
for a new array, when you actually want a view with strides, doesn't
sound like an obvious explanation for "order".
slightly more difficult:
order = "I don't care" (aka. order="K") means: "I want a view in whichever order
of the values, but please try harder not to copy any memory"
This also doesn't refer to the memory of a *new* array, if it is
> NumPy-Discussion mailing list
More information about the NumPy-Discussion