[Numpy-discussion] Memory layout of record arrays

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



Hello,

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

True

Is there any obvious solution that I missed ?


Nicolas


More information about the NumPy-Discussion mailing list