[SciPy-user] numpy array in ctype struct

Rob Hetland hetland@tamu....
Tue Jan 22 01:17:51 CST 2008


On Jan 21, 2008, at 8:17 PM, Travis E. Oliphant wrote:

> You might find PyArray_AsCArray useful.


Travis-

Indeed, that was what I needed to get it to work right.  For  
posterity, here is what I did.  I know I need a 2D array, so much of  
the complexity in PyArray_AsCArray could be taken out.  I will also  
assume a contiguous array, so that my function looks something like  
this:


void* function_wrap(double *pts1, int nPts, int dim) {

     int i;
     double **pts;

     pts = (double **)malloc(nPts * sizeof(double *));
     for (i=0; i<nPts; i++) {
         pts[i] = pts1 + i*dim;
     }

     ///  Call and return result from some function that needs **pts

}



Are there any pitfalls to this approach?  It seems to work perfectly  
for the test cases I have done.

Thanks for the tip,

-Rob

----
Rob Hetland, Associate Professor
Dept. of Oceanography, Texas A&M University
http://pong.tamu.edu/~rob
phone: 979-458-0096, fax: 979-845-6331




More information about the SciPy-user mailing list