I certainly think that something along these lines would be possible. However, in the end I just decided to keep track of the indices using a Python dictionary, which means to access A[-3] I actually have to call A[index[-3]]. A little clunkier, but I was worried that the other solutions would be brittle in the long run.

Thanks for all of the comments.

On May 30, 2006, at 2:04 PM, David Huard wrote:

Just a thought:
would it be possible to overload the array __getitem__ method ?

I can do it with lists, but not with arrays...

For instance,

class fortarray(list):
    def __getitem__(self, index):
        return list.__getitem__(self, index+5)

and
>>> l = fortarray()
>>> l.append(1)
>>> l[-5]
1

There is certainly a more elegant way to define the class with the starting index as an argument, but I didn't look into it. For arrays, this doesn't work out of the box, but I'd surprised if there was no way to tweak it to do the same.

Good luck
David

2006/5/30, Rick Muller <rmuller@sandia.gov>:
Indeed I am. Thanks for the reply
On May 30, 2006, at 11:32 AM, Rob Hetland wrote:

>
> I believe Rick is talking about negative indices (possible in
> FORTRAN), in which case the answer is no.
>
> -Rob
>
> On May 30, 2006, at 11:28 AM, Rick Muller wrote:
>
>> Is it possible to create arrays that run from, say -5:5, rather
>> than 0:11? Analogous to the Fortran "allocate(A(-5:5))" command?
>> I'm translating a F90 code to Python, and it would be easier to do
>> this than to use a python dictionary.
>
> -----
> Rob Hetland, Assistant Professor
> Dept of Oceanography, Texas A&M University
> p: 979-458-0096, f: 979-845-6331
> e: hetland@tamu.edu, w: http://pong.tamu.edu
>
>

Rick Muller
rmuller@sandia.gov






-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


Rick Muller
rmuller@sandia.gov