[Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Mark Bakker
Hello list, 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 b[:-n] If I need all terms in the array, the logical syntax would be: b[:-0] but that doesn't work. Any reason why that has not been implemented? Any elegant

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Sebastian Walter
I'm sure there is a better solution: In [1]: x = numpy.array([i for i in range(10)]) In [2]: foo = lambda n: -n if n!=0 else None : In [3]: x[:foo(1)] Out[3]: array([0, 1, 2, 3, 4, 5, 6, 7, 8]) In [4]: x[:foo(0)] Out[4]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) On Wed, Aug 19, 2009

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Citi, Luca
The problem is that n is integer and integer do not have different representations for 0 and -0 (while floats do). Therefore it is impossible to disambiguate the following two case scenarios: b[:n] # take the first n b[:-n] # take all but the last n when n ==0. One possible solution (you

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Neil Martinsen-Burrell
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 b[:-n] If I need all terms in the array, the logical syntax would be: b[:-0] but that doesn't work. Any reason why that

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Citi, Luca
Another solution (elegant?? readable??) : x[slice(-n or None)] # with n == 0, 1, ... ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Sebastian Walter
In [45]: x[: -0 or None] Out[45]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) In [46]: x[: -1 or None] Out[46]: array([0, 1, 2, 3, 4, 5, 6, 7, 8]) works fine without slice() On Wed, Aug 19, 2009 at 2:54 PM, Citi, Lucalc...@essex.ac.uk wrote: Another solution (elegant?? readable??) : x[slice(-n or

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread Mark Bakker
The winner so far: x[: -n or None] works fine when n = 0, relatively elegant, even pretty slick I think. And I expect it to be quick. Thanks for all the replys, Mark ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?.

2009-08-19 Thread Travis Oliphant
Use N = len(b) and then b[:N-n] -Travis -- (mobile phone of) Travis Oliphant Enthought, Inc. 1-512-536-1057 http://www.enthought.com On Aug 19, 2009, at 7:25 AM, Mark Bakker mark...@gmail.com wrote: Hello list, I compute the index of the last term in an array that I need and call the

Re: [Numpy-discussion] why does b[:-0] not work, and is there an elegant solution?

2009-08-19 Thread David Cournapeau
On Wed, Aug 19, 2009 at 5:50 AM, Neil Martinsen-Burrelln...@wartburg.edu wrote: 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 b[:-n] If I need all terms in the array, the