[Numpy-discussion] Numpy array from ctypes pointer object?

Mark Heslep mark at mitre.org
Wed Jul 12 15:06:14 EDT 2006


Travis Oliphant wrote:
> Mark Heslep wrote:
>> I don't see a clean way to create a numpy array from a ctypes pointer 
>> object. Is the __array_interface_ in ctypes the thing thats missing 
>> needed to make this happen?  I've followed Albert's  Scipy cookbook 
>> on ctypes here
>>
>> On the C side the PyArray_SimpleNewFromData( ..dimensions, ...data 
>> ptr) C API does the job nicely.  Is there a ctypes paradigm for 
>> SimpleNew...?
>>   
> Can you somehow call this function using ctypes?
>
> -Travis
That might work, though indirectly.  As I think I understand from ctypes 
docs:  Ctypes uses functions exposed in a  shared library, macros 
existing only a header are not available.  If its PyArray... is a macro 
then I a) need to compile and make a little library directly from 
arrayobject.h or b) need to use the root function upon which the macro 
is based, PyArrayNew?

ctypes has built-in access to the functions in the core python library,  
but Im not sure which library contains all the PyArray API calls, since 
its all typically hidden by  distutils and setup.py

Mark






More information about the NumPy-Discussion mailing list