On Thu, Jul 28, 2011 at 4:26 PM, Derek Homeier
<[email protected]> wrote:
>> I guess the kind of problem I struggle with more frequently is books
>> written with summations over -m to +n. In those cases, it's often
>> convenient to use the mapping function, so that I can enter the
>> formulas as they occur.
>
> I don't want to open any cans of worms at this point, but given that
> Fortran90 supports such indexing (arbitrary limits, including negative ones),
> there definitely are use cases for it (or rather, instances where it is very
> convenient at least, like in Stéfan's books). So I am wondering how much it
> would take to implement such an enhancement for the standard ndarray...
Thinking about it, expanding on Anne's solution and the fact that
Python allows negative indexing, you can simply reshuffle the array
after operations a bit and have everything work out.
import numpy as np
n = -5
m = 7
x = np.zeros((m - n), dtype=float)
# Do some operation with n..m based indexing
for i in range(-5, 7):
x[i] = i
# Construct the output
x = np.hstack((x[n:], x[:m]))
print x
Regards
Stéfan
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion