Passing a NumPy array to a C function

Just a note to myself: http://stackoverflow.com/questions/3046305/simple-wrapping-of-c-code-with-cython has a nice self-contained example of passing a NumPy array to C. And some comments about being aware of non-contiguous arrays or Fortran indexing.

I used this example at work recently to optimize a nested inner for-loop in a statistical bootstrap program and the Python/Cython/C version runs 15 times faster than the plain Python code. The GNU Scientific Library has some convenient random number generators.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s