3

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.