[Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?
Wed Aug 19 07:50:46 CDT 2009
On Aug 19, 2009, at 7:25 AM, Mark Bakker wrote:
> I compute the index of the last term in an array that I need and
> call the index n.
> I can then call the array b as
> If I need all terms in the array, the logical syntax would be:
> but that doesn't work. Any reason why that has not been implemented?
> Any elegant workaround?
Because there is no negative zero as an integer:
>>> -0 == 0
So when Python parses your request, it sees "-0" and replaces that
with the integer 0. And as you found out, b[:0] gives you an empty
slice. Negative indices are just syntactic sugar for (N+1)-n where N
is the length of the list and that should work for n=0 as well:
>>> b = [1,2,3,4,5]
[1, 2, 3, 4, 5]
More information about the NumPy-Discussion