我有以下课程:
class PyWav {
public:
static inline boost::python::object sdVecToNumpyArray(std::vector<double> const& vec)
{
npy_intp size = vec.size();
double * data = size ? const_cast<double *>(&vec[0]) : static_cast<double *>(NULL);
PyObject * pyObj = PyArray_SimpleNewFromData(1, &size, NPY_DOUBLE, data);
boost::python::handle<> handle ( pyObj );
boost::python::numeric::array arr(handle);
return arr.copy();
}
// Access function
inline boost::python::numeric::array toNumPy()
{
std::vector<double> v = Signal(); // get the vector
boost::python::numeric::array arr = Lib::python::PyWav::sdVecToNumpyArray(
v);
return arr;
}
};
问题是我不知道如何访问 stdVecToNumpyArray 并传递向量?我希望方法“toNumPy()”向用户开放,但不是 sdVecToNumpyArray
我收到以下错误:
错误:请求从“boost::python::api::object”转换为非标量类型“boost::python::numeric::array”
五);
有人有主意吗?
您可能需要显式强制转换,如下所示:https://mail.python.org/pipermail/cplusplus-sig/2009-January/014194.html https://mail.python.org/pipermail/cplusplus-sig/2009-January/014194.html
boost::python::numeric::array arr(static_cast<boost::python::numeric::array>(handle));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)