[Numpy-discussion] ndarray __getattr__ to perform __getitem__

Pauli Virtanen pav@iki...
Fri Oct 29 10:05:18 CDT 2010

Fri, 29 Oct 2010 09:58:33 -0400, Ian Stokes-Rees wrote:
> 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 "__getattr__(self,attr)" method to the class.  If someone can
> point me in the right direction, I'll keep looking into this, otherwise
> I'm giving up and will just try and use recarray.


The Python documentation doesn't seem to say very if method/attribute 
slots are consulted before falling back to tp_getattro. If tp_getattro is 
consulted first, then implementing it will lead to a performance hit.

I'd probably be +0 on providing recarray-like functionality on ordinary 
ndarrays, if it can be done without (significant) performance issues.

Pauli Virtanen

More information about the NumPy-Discussion mailing list