Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Ian Stokes-Rees
But wouldn't the performance hit only come when I use it in this way? __getattr__ is only called if the named attribute is *not* found (I guess it falls off the end of the case statement, or is the result of the attribute hash table miss). That's why I said that __getattr__ would perhaps

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Pauli Virtanen
Hi, Fri, 29 Oct 2010 05:59:07 -0400, Ian Stokes-Rees wrote: But wouldn't the performance hit only come when I use it in this way? __getattr__ is only called if the named attribute is *not* found (I guess it falls off the end of the case statement, or is the result of the attribute hash table

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Zachary Pincus
But wouldn't the performance hit only come when I use it in this way? __getattr__ is only called if the named attribute is *not* found (I guess it falls off the end of the case statement, or is the result of the attribute hash table miss). That's why I said that __getattr__ would

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Ian Stokes-Rees
Note that there are various extant projects that I think attempt to provide similar functionality to what you're wanting (unless I badly misread your original email, in which case apologies): http://projects.scipy.org/numpy/wiki/NdarrayWithNamedAxes Having looked into it more, I think

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Pierre GM
On Oct 29, 2010, at 3:58 PM, Ian Stokes-Rees wrote: Note that there are various extant projects that I think attempt to provide similar functionality to what you're wanting (unless I badly misread your original email, in which case apologies):

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-29 Thread Pauli Virtanen
Fri, 29 Oct 2010 09:58:33 -0400, Ian Stokes-Rees wrote: [clip] I've spent an hour looking at the numpy code (my first time), and I don't see any obvious way to do this, since ndarray is (AFAICT) a pure-C object with auto-generated wrappers, which seems to preclude (easily) adding a

[Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-28 Thread Ian Stokes-Rees
I have an ndarray with named dimensions. I find myself writing some fairly laborious code with lots of square brackets and quotes. It seems like it wouldn't be such a big deal to overload __getattribute__ so instead of doing: r = genfromtxt('results.dat',dtype=[('a','int'), ('b', 'f8'),

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-28 Thread Robert Kern
On Thu, Oct 28, 2010 at 15:17, Ian Stokes-Rees ijsto...@hkl.hms.harvard.edu wrote: I have an ndarray with named dimensions.  I find myself writing some fairly laborious code with lots of square brackets and quotes.  It seems like it wouldn't be such a big deal to overload __getattribute__ so

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-28 Thread Ian Stokes-Rees
On 10/28/10 5:29 PM, Robert Kern wrote: On Thu, Oct 28, 2010 at 15:17, Ian Stokes-Rees ijsto...@hkl.hms.harvard.edu wrote: I have an ndarray with named dimensions. I find myself writing some fairly laborious code with lots of square brackets and quotes. It seems like it wouldn't be such a

Re: [Numpy-discussion] ndarray __getattr__ to perform __getitem__

2010-10-28 Thread Robert Kern
On Thu, Oct 28, 2010 at 16:37, Ian Stokes-Rees ijsto...@hkl.hms.harvard.edu wrote: On 10/28/10 5:29 PM, Robert Kern wrote: On Thu, Oct 28, 2010 at 15:17, Ian Stokes-Rees ijsto...@hkl.hms.harvard.edu wrote: I have an ndarray with named dimensions.  I find myself writing some fairly laborious