multidimensional arrays from python to C

Terry Reedy tjreedy at udel.edu
Wed May 29 13:18:07 EDT 2002


"Chris Fonnesbeck" <spam at fisher.forestry.uga.edu> wrote in message
news:c3835e5f.0205290827.2e7ede69 at posting.google.com...
> I am embedding some python code in C, and need to be able to take a
> multidim. array from python and assign its values to a global double
> array in C.  Can this python array simply be cast into a C double
> type, and assigned to the array in question, or do I have to do a
> multiple-nested loop to assign each element individually.  Hope this
> makes sense!
>
> For example, in C I have:
>
> double Fall[NA][NS][NG][NC][NP], where N* are constants
>
> and I have pulled in my python 5-dimensional array with:
>
> parray = (PyArrayObject *)(PyEval_CallObject(pmeth,pargs));
>
> How do I get these values into Fall?

In C terms, the Python array is an array of arrays of ... arrays of
pointers to PyObjects containing float (double) values.  So you would
have to copy.  Perhaps Numerical Python would be of assistance to you.

TJR





More information about the Python-list mailing list