[Numpy-discussion] Support for understand ctypes data-types now in SVN

Stefan van der Walt stefan at sun.ac.za
Fri Nov 17 14:05:34 CST 2006

On Fri, Nov 17, 2006 at 12:43:45PM -0700, Travis Oliphant wrote:
> The NumPy dtype command now understands ctypes data-types including 
> derived structures and arrays.
> This means you can specify data-types using ctypes method of building 
> structures and pass those classes whenever NumPy expects a data-type 
> object.
> Simple example:
> import ctypes as ct
> import numpy as np
> np.array([1,2,3],ct.c_short)
> More complicated:
> class POINT(ct.Structure):
>          _fields_ = [("x", ct.c_int),
>                            ("y", ct.c_int)]
> np.array([(3,4),(5,6),(7,8)], dtype=POINT)

Is the memory layout of the array above the same as what an array of
POINTs would be in C, or are they not padded?  If not, is

dtype(POINT,align=True) supported?

Or am I rather looking for


or are they equivalent in terms of memory use?

The reason I ask is because this would make it very easy to allocate
fairly complex C structures on the python side when wrapping.

Good stuff, thanks!


More information about the Numpy-discussion mailing list