简体   繁体   中英

Pass simple numpy array to C via SWIG

I want to pass numpy array of known size and type via SWIG to C function

# .py
data = numpy.arange( N , dtype=numpy.int32 )
external_c_function( data )

# .i
extern void external_c_function( int32_t* data );

# .c
void external_c_function( int32_t* data)
{
    // ...
}

Unfortunately, I will get an error:

TypeError: in method 'external_c_function', argument 1 of type 'int32_t *'

What is the easiest way to pass numpy array to SWIG?

You can use numpy.i . Just have a look at http://www.scipy.org/Cookbook/SWIG_NumPy_examples

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM