[Numpy-discussion] inheriting from recarray with nested dtypes

Geoffrey Irving irving at naml.us
Thu Mar 28 14:16:48 EDT 2013

I have the following two structured dtypes:

    rotation (quaternion) = dtype([('s','f8'),('v','3f8')])
    frame = dtype([('t','3f8'),('r',rotation)])

For various reasons, I usually store rotation arrays in a class
Rotations deriving from ndarray, and frames in a class Frames deriving
from ndarray.

Currently I am defining .s, .v, .t, and .r properties manually, and
I'd like to switch to inheriting from recarray.  However, the .r
property should return an array of class Rotations.  I.e.,

    f = Frames(...) # f.dtype = frame
    r = f.r # r.dtype = rotation, type(r) = Rotations

Is there a clean way to tell recarray to adjust the type returned?  It
already has a bit of intelligence there, since it returns ndarray vs.
recarray based on whether the returned dtype has fields.

The full code is here in case anyone is curious:



More information about the NumPy-Discussion mailing list