[Numpy-discussion] possible enhancement to getitem?

Mike Ressler mike.ressler at alum.mit.edu
Fri Jun 8 11:52:43 EDT 2012

> On 08/06/12 14:14, Neal Becker wrote:
>> The fact that this proposed numpy behavior would not match python list behavior
>> holds little weight for me.  I would still favor this change, unless it added
>> significant overhead.  My opinion, of course.

As a "Joe User", I think using the [-2:2] syntax would be a mistake,
though I agree it would be a useful shortcut (e.g. FFTs or power
series where you need to wrap around). My concern is this: in a
multiple dimension case, which are the -2 and -1 that you really want?
Example, in a 2-D image that is constructed by reshaping a series of
samples ordered in time, there are occasions where I would want the
first two and last two samples of the same row (looking at spatial
effects), and other times where I want the right two samples of the
preceding row and the left two samples of the next row (looking at
time effects). Which is the correct interpretation? It may be obvious
to most people that it is "from the same row", but that isn't so
obvious to me.

Actually, my own preference would be that this construction throws an
exception as a malformed slice, and I really wonder why python itself
doesn't do this.


mike.ressler at alum.mit.edu

More information about the NumPy-Discussion mailing list