[Numpy-discussion] PyArray_DescrConverter - alignment / trailing unused bytes
Francesc Altet
faltet at carabos.com
Fri Sep 15 10:40:39 EDT 2006
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])
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,
--
>0,0< Francesc Altet http://www.carabos.com/
V V Cárabos Coop. V. Enjoy Data
"-"
More information about the NumPy-Discussion
mailing list