Suppose:
using namespace boost::python;
void myClass::test(numeric::array& arrayParam) {
const tuple &shape = extract<tuple>(arrayParam.attr("shape"));
}
I would like to transform it to an int and print for example. I tried int x = shape[0];
but it gives me a "cannot convert ‘boost::python::api::const_object_item’ to ‘int’ in initialization" message.
shape[0]
gives you a Python object. To convert it to an int
or another C++ type, you need to extract the value:
int x = extract<int>(shape[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With