[Numpy-discussion] Memory layout of record arrays

Nicolas Rougier Nicolas.Rougier@loria...
Thu Jul 30 10:53:01 CDT 2009


I've been using record arrays to create arrays with different types  
and since I'm doing a lot of computation on each of the different  
fields, the default memory layout does not serve my computations.  
Ideally, I would like to have record arrays where each field is a  
contiguous block of memory. I searched the dtype documentation but did  
not find anything about it. In the meantime,  I wrote a class that  
emulates this behavior, but it does not inherit from nd.array and I  
need inheritance.

To sum up, I would like to have:

 >>> Z = np.zeros(3, dtype=[('x',np.float32), ('y',np.int)])

 >>> print Z['x'].flags[['C_CONTIGUOUS']

False <= should be True

 >>> print Z['y'].flags[['C_CONTIGUOUS']

False <= should be True

 >>> Z.shape == Z['x'].shape == Z['y'].shape


Is there any obvious solution that I missed ?


More information about the NumPy-Discussion mailing list