boost-python

how to return numpy.array from boost::python?

血红的双手。 提交于 2019-11-26 09:08:54
问题 I would like to return some data from c++ code as a numpy.array object. I had a look at boost::python::numeric , but its documentation is very terse. Can I get an example of e.g. returning a (not very large) vector<double> to python? I don\'t mind doing copies of data. 回答1: UPDATE: the library described in my original answer (https://github.com/ndarray/Boost.NumPy) has been integrated directly into Boost.Python as of Boost 1.63, and hence the standalone version is now deprecated. The text

std::vector to boost::python::list

我是研究僧i 提交于 2019-11-26 07:26:23
问题 I have a method in c++ that gets called from python and needs to return a python list object. I have already created the method, and its attached to an exposed class and callable from python right now... (it returns void). So the question is, how do I create a python list from this: std::vector<std::string> results; I am not really understanding how the constructor works from this documentation: http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/list.html Also... I don\'t really want to

How can I implement a C++ class in Python, to be called by C++?

落爺英雄遲暮 提交于 2019-11-26 03:50:22
问题 I have a class interface written in C++. I have a few classes that implement this interface also written in C++. These are called in the context of a larger C++ program, which essentially implements \"main\". I want to be able to write implementations of this interface in Python, and allow them to be used in the context of the larger C++ program, as if they had been just written in C++. There\'s been a lot written about interfacing python and C++ but I cannot quite figure out how to do what I