[SciPy-user] How to: Pass NumPy arrays to C & use SWIG to generate modules

Gael Varoquaux gael.varoquaux at normalesup.org
Tue Dec 5 10:14:07 CST 2006

On Tue, Dec 05, 2006 at 07:38:01AM -0800, Lou Pecora wrote:
> This remains a frustration with Python.  I absolutely
> love the language and code as much of my numerical
> work in it as I can, but extending it remains a
> frustrating barrier.  This despite spending several
> full days looking into Guido's tutorial on extensions,
> SWIG, and lots of googling.  


I am not a very advanced python user. I do not master writing C
extentions. I have tried simple things, and had success with them because
they were simple enough for me. In order of difficulty this is what I

- scipy.weave (great, but won't probably suit your purposes, have a look
  at the wiki page)

- pyrex (same reamrk than above, though the concept is fabulous)

- passing array to C code with ctypes. I think this can suit you. It
  might not be as versatile or powerful as SWIG, but I found it was
  simple enough for my limited knowledge. I started out with simple hello
  word C functions, and was able to pass numpy arrays back and forth
  between numpy and C thanks to Albert Strasheim's wiki page

I cannot help you out with SWIG, as I have decided it was to complicated
for me so far.


More information about the SciPy-user mailing list