[Numpy-discussion] swig and Numeric

Scott Ransom ransom at cfa.harvard.edu
Wed Aug 8 00:54:49 EDT 2001

"Paul F. Dubois" wrote:
> Does someone have an example of using SWIG to connect Numeric arrays to C code
> that expects double* arguments?

Hi Paul,

I have a fairly comprehensive set of typedefs (including 1-D and 2-D
array input and output) for interfacing Numeric arrays here:


As an example, say you have a function with a prototype:

int foo(double *array, int len_array);

You would simply make a ".i" file with the following:

%module foo
%include numpy.i 

%apply double* IN_1D_DOUBLE { double *array };
int bar(double *array, int len_array);


Run swig on it, compile it, and import it.

Hope this helps,


Scott M. Ransom                   Address:  Harvard-Smithsonian CfA
Phone:  (617) 496-7908                      60 Garden St.  MS 10 
email:  ransom at cfa.harvard.edu              Cambridge, MA  02138
GPG Fingerprint: 06A9 9553 78BE 16DB 407B  FFCA 9BFA B6FF FFD3 2989

More information about the NumPy-Discussion mailing list