简体   繁体   English

Boost.Python - 向量到Numpy数组

[英]Boost.Python - Vector to Numpy Array

I have the following class: 我有以下课程:

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;
   }

}; 

The problem is I do not know how to access the stdVecToNumpyArray and pass through the vector? 问题是我不知道如何访问stdVecToNumpyArray并通过向量? I want the method "toNumPy()" to be open to the user, but, not the sdVecToNumpyArray 我希望方法“toNumPy()”对用户开放,但不是sdVecToNumpyArray

I get the following error: 我收到以下错误:

error: conversion from 'boost::python::api::object' to non-scalar type 'boost::python::numeric::array' requested v); 错误:从'boost :: python :: api :: object'转换为非标量类型'boost :: python :: numeric :: array'请求v);

Anyone have any ideas? 有人有主意吗?

您可能需要一个明确的演员表,例如: https//mail.python.org/pipermail/cplusplus-sig/2009-January/014194.html

boost::python::numeric::array arr(static_cast<boost::python::numeric::array>(handle));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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