[C++-sig] Accessing 2D array from python in C++

alfa alfarobi0161 at yahoo.com
Wed Aug 22 12:13:34 CEST 2012


Hi John,

Thanks a lot for your implementation. In multi_array_to_numpy.h,  can you give more hints on which method/function that I can possibly use if I can include it in my implementation as a header file. 

Thanks in advance.




________________________________
 From: John Reid <j.reid at mail.cryst.bbk.ac.uk>
To: cplusplus-sig at python.org 
Sent: Thursday, August 16, 2012 5:02 PM
Subject: Re: [C++-sig] Accessing 2D array from python in C++
 
If you don't mind digging around in my code, you could download the
source code for the STEME python package from pypi and look in the
c++/myrrh directory. There is code to access multi_arrays from python in
there.

http://pypi.python.org/pypi/STEME/

In particular the file
c++/myrrh/myrrh/python/multi_array_to_numpy.h contains the bulk of the
implementation.

HTH,
John.



On 16/08/12 09:29, alfa wrote:
> Hi,
> 
> Could you give more hints on this or any code snippet that I can
> implement this. I'm a bit naive in applying this. Please consider my 2D
> array of Vp_cpp(Vp equivalent in Python) is as below:
> 
>     typedef boost::multi_array<double, 2> array_type;
>     typedef array_type::index index;
>     array_type Vp_cpp(boost::extents[X_cpp][X_cpp]);
> 
> 
> I'm still puzzled how to "manually wrap the features" in the last "..." in:
>     boost::python::class_< boost::multi_array<...> >(...)
> 
> Thanks in advance.
> 
> ------------------------------------------------------------------------
> *From:* Jim Bosch <talljimbo at gmail.com>
> *To:* alfa <alfarobi0161 at yahoo.com>
> *Cc:* Development of Python/C++ integration <cplusplus-sig at python.org>
> *Sent:* Wednesday, August 15, 2012 5:34 PM
> *Subject:* Re: [C++-sig] Accessing 2D array from python in C++
> 
> On Aug 15, 2012 1:57 AM, "alfa" <alfarobi0161 at yahoo.com
> <mailto:alfarobi0161 at yahoo.com>> wrote:
>>
>> I apologize for double posting this because it was spammed before.
>>
>> Hi Jim,
>>
>> Do you mean, "you could wrap multi_array itself using class_", I
> should do as below:
>>
>> boost::python::class_<std::vector<std::vector<double> >
>>("PyVec").def(boost::python::vector_indexing_suite<std::vector<std::vector<double>
>> >());
>>
> No, I don't think that will work; I meant something like this:
> boost::python::class_< boost::multi_array<...> >(...)
>     ...;
> Where the last "..." is where you have to manually wrap the features of
> multi_array you want to use.  I'm afraid there's nothing as easy as
> vector_indexing_suite.
> Jim
> 
> 
> 
> 
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
> 

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120822/c679fa61/attachment.html>


More information about the Cplusplus-sig mailing list