On Friday 15 September 2006 16:40, Francesc Altet wrote: > A Divendres 15 Setembre 2006 16:13, Martin Wiechert va escriure: > > Hi list, > > > > I'm using PyArray_DescrConverter with a dict object to create a > > "struct-like" dtype from C. > > As the struct contains different data types I run into "unaligned access" > > problems. > > Is there a way to force alignment or to get trailing unused bytes in the > > dtpye? > > One possible solution is to declare void ('V' charcode) types for filling > the gaps. For example: > > > In [118]: ra=numpy.rec.array("1"*300, > dtype=[('sval','<a4'),('unused','|V4'), ('dval','<f8')], shape=2) > > In [119]: ra['sval'] > Out[119]: > recarray([1111, 1111], > dtype='|S4') > > In [120]: ra['dval'] > Out[120]: array([ 9.73041595e-72, 9.73041595e-72]) >
Hm, not exactly elegant but should work. Thanks Francesc! Note that all but trailing gaps can be controlled using a dictionary descriptor with an offsets key: >>> ra = zeros ((10,), dtype = {'names': ['sval', 'dval'], 'formats': ['<a4', '<f8'], 'offsets': [0, 8]}) >>> ra.dtype dtype([('sval', '|S4'), ('', '|V4'), ('dval', '<f8')]) Still if anybody knows a clean solution I would be very interested. > You can still access the empty spaces if you want (although it is > nonsense): > > In [121]: ra['unused'] > Out[121]: > recarray([1111, 1111], > dtype='|V4') > > Cheers, ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion