Getting double* from NumPy array?

Thomas Wouters thomas at xs4all.nl
Tue Jun 27 03:55:44 EDT 2000


On Mon, 26 Jun 2000 13:23:50 -0700, Ted Drain <ted.drain at jpl.nasa.gov> wrote:
>I have some existing C/C++ code that can accept a double array ( int len,
>and double* ptr) to do some processing.  I want to allow users to create
>arrays in python using NumPy and then provide an interface to pass these
>arrays to my C/C++ code.  

>Assuming a 1-dimensional NumPy array, is there an easy way to extract a
>pointer to a double and length from the python object?  The C/C++ isn't
>going to change the object so I'd prefer not to make a copy of it.

NumPy not withstanding (I don't really know it) but doesn't the 'array'
module do what you're looking for ? It won't allow you to store the length
in the same structure, so you'll have to pass that seperately (or convert it
to a double and store it as the first element) but it does give direct
access to the stored values, using the ob_items member.

But I'm sure NumPy has a similar method ;)



More information about the Python-list mailing list