On Wed, Aug 19, 2009 at 5:50 AM, Neil Martinsen-Burrell
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 lo
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 wrote:
> Hello list,
>
> I compute the index of the last term in an array that I need and
> call the index n.
>
> I c
Hi,
I've coded a function that allows to extract a contiguous array from
another one using a given shape and centered on a given position. I
did not find an equivalent within numpy so I hope I did not miss it.
The only interest of the function is to guarantee that the resulting
sub-array
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
http://mail.scipy.org/m
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, Luca wrote:
> Another solution (elegant?? readable??) :
>>> x[slice(-n or None)] # with n
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
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
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
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
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 workaroun
10 matches
Mail list logo