[SciPy-user] numpy array in ctype struct

Matthieu Brucher matthieu.brucher@gmail....
Sun Jan 20 03:01:12 CST 2008


>
> How do you pass ndarrays of arbitrary size.  I would like to have
> some C code like:
>
> extern void bar(double **data, int L, int M) {
>      ...
> }
>
> The code needs to pass the array on to another library as a **double,
> and I cannot seem to get ctypes to pass a 2 dimensional array to the
> subroutine.  Arrays if fixed size seem to work fine, and single
> dimensional *doubles also work fine, even when passing
> multidimensional numpy.ndarrays.
>
> But, how to pass an arbitrary (two-dimensional) numpy.ndarray as a
> **double?


This function signature suppose that you will access an element by
data[i][j] which is not the way Numpy works. You can create a wrapper
function that will allocate a double** 1D array pointing to the adequate
*double (start of a line), pass it to your function and then deallocate the
array when returning from the function.

Matthieu
-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080120/6ea74e18/attachment.html 


More information about the SciPy-user mailing list