[Numpy-discussion] How to export a CObject from NumPy to my own module?

Christopher Barker Chris.Barker@noaa....
Wed Nov 24 11:59:50 CST 2010

On 11/24/10 9:35 AM, NumPyStudent wrote:
> Well, I believe I should problably use the PyArray_API instead
> (http://www.velocityreviews.com/forums/t358140-re-dynamically-loaded-libraries.html),
> since it seems it's implemented in NumPy for this exact reason(?).
> Can anyone point me in the direction of a good step-step guide og using this
> api to export function pointers from NumPy to your own modules?

It's not clear to me what you really are trying accomplish here. A 
little more detail about your problem may help.

If what you are trying to do is write a C-extension that can take numpy 
arrays as input, and/or provide them as output, while working natively 
with the data inside them in C, then yes, working with the numpy C api 
is the way to go.

However, I suggest you take a look at Cython:


It provides a much easier way to write python extensions, and has 
build-in understanding of numpy arrays. It can call arbitrary C code so 
there are no limits to its functionality, but it will save you much pain 
in reference coutning, converting to/from python objects, etc.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the NumPy-Discussion mailing list