Thanks, this is pretty much what I ended up doing.
Once I got that into python, I converted it to a narray

 

-----Original Message-----
From: cplusplus-sig-bounces+enrico.ng=lmco....@python.org 
[mailto:cplusplus-sig-bounces+enrico.ng=lmco....@python.org] On Behalf Of Jim 
Bosch
Sent: Thursday, January 21, 2010 4:17 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Arrays to python

On Thu, 2010-01-21 at 09:10 -0500, Ng, Enrico wrote:
> I had hoped that there was something simple after seeing the numeric part in 
> the documentation.

Well, if you're content with a 1-D array and speed isn't a big issue,
you can just copy the elements of your array into a Python list like
this:

boost::python::list py_get_data() {
    boost::python::list r;
    for (int n=0; n<IMAGE_SIZE; ++n) {
        r.append(get_data()[n]);
    }
    return r;
}

If you want two dimensions, you could make a list-of-lists.
I don't think there's any way to get a C array into a Python object
without lots of explicit copying aside from using numpy.


Jim Bosch


_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to