<div dir="ltr">On Wed, Aug 31, 2016 at 1:34 PM, Matti Viljamaa <<a href="mailto:mviljamaa@kapsi.fi">mviljamaa@kapsi.fi</a>> wrote:<br>><br>> On 31 Aug 2016, at 15:22, Robert Kern <<a href="mailto:robert.kern@gmail.com">robert.kern@gmail.com</a>> wrote:<br>><br>> On Wed, Aug 31, 2016 at 12:28 PM, Matti Viljamaa <<a href="mailto:mviljamaa@kapsi.fi">mviljamaa@kapsi.fi</a>> wrote:<br>> ><br>> > Is there a clean way to include the last element when subindexing numpy arrays?<br>> > Since the default behaviour of numpy arrays is to omit the “stop index”.<br>> ><br>> > So for,<br>> ><br>> > >>> A<br>> > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])<br>> > >>> A[0:5]<br>> > array([0, 1, 2, 3, 4])<br>><br>> A[5:]<br>><br>> --<br>> Robert Kern<br>><br>> No that returns the subarray starting from index 5 to the end.<br>><br>> What I want to be able to return<br>><br>> array([0, 1, 2, 3, 4, 5])<br>><br>> (i.e. last element 5 included)<br>><br>> but without the funky A[0:6] syntax, which looks like it should return<br>><br>> array([0, 1, 2, 3, 4, 5, 6])<br>><br>> but since bumpy arrays omit the last index, returns<br>><br>> array([0, 1, 2, 3, 4, 5])<br>><br>> which syntactically would be more reasonable to be A[0:5].<br><br>Ah, I see what you are asking now.<div><br></div><div>The answer is "no"; this is just the way that slicing works in Python in general. numpy merely follows suit. It is something that you will get used to with practice. My sense of "funkiness" and "reasonableness" is the opposite of yours, for instance.<br><br>--<br>Robert Kern</div></div>