[Numpy-discussion] possible enhancement to getitem?

Robert Kern robert.kern at gmail.com
Thu Jun 7 15:00:40 EDT 2012


On Thu, Jun 7, 2012 at 7:55 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> In [3]: u = np.arange(10)
>
> In [4]: u
> Out[4]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>
> In [5]: u[-2:]
> Out[5]: array([8, 9])
>
> In [6]: u[-2:2]
> Out[6]: array([], dtype=int64)
>
> I would argue for consistency it would be desirable for this to return
>
> [8, 9, 0, 1]

Unfortunately, this would be inconsistent with Python semantics:

[~]
|1> u = range(10)

[~]
|2> u[-2:2]
[]

-- 
Robert Kern



More information about the NumPy-Discussion mailing list