[SciPy-user] numpy array in ctype struct
Thomas Heller
theller at ctypes.org
Tue Jan 15 11:29:31 EST 2008
Travis E. Oliphant schrieb:
> Paul Kienzle wrote:
>> Hi,
>>
>> We are trying to create the following struct in ctypes:
>>
>> struct {
>> int n,k;
>> double A[4][4], B[4][4];
>> } ;
>>
>> Easy enough:
>>
>> class embedded_array(Structure):
>> _fields_ = [("n",c_int),("k",c_int),("A",c_double*16),("B",c_double*16)]
>> instance = embedded_array()
>>
>> Question:
>>
>> Is there a way to map the data in A/B into a numpy array, so that we
>> can use it directly?
>>
>>
> Yes. You can create an array from a pointer to memory and a
> description of the data that is much like the ctypes structure. At
> some point, there should be a direct conversion from ctypes objects to
> NumPy data-types, but nobody has written that yet.
[...]
Is there anything that should be added to ctypes (Python 2.6 isn't too
far away) that would help with this conversion?
Thanks,
Thomas
More information about the SciPy-User
mailing list