简体   繁体   中英

C++ Python convert data from vector to ndarray

I am creating a C++ project which includes some python. I have used boost::python but now I am stuck. I have some data stored in a std::vector . The data should be send to python to do some calculations. The Python NumPy functions I use need the data in ndarray format, so I need a way to convert it. Since I want to do some more things with the results in C++ I want to convert the result back from ndarray to std::vector .

How can I convert std::vector to ndarray and vice versa? Can anyone post some sample code? I know there is a lib called boost.numpy out there, but are there other ways, because I was not able to build this lib...

Can I use boost::python::numeric for the job? Can anyone provide sample code?

Is it possible without copying data?

Maybe you are willing to use the C Numpy API .

You should look at C/C++ PyArray_SimpleNewFromData to create brand new ndarray in your c++ code.

This post may help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM