Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在用c++;特征库输出错误 我需要将NUMPY数组传递给C++函数,处理它并返回另一个NUMPY数组。_Python_C++_Arrays_Numpy - Fatal编程技术网

Python 在用c++;特征库输出错误 我需要将NUMPY数组传递给C++函数,处理它并返回另一个NUMPY数组。

Python 在用c++;特征库输出错误 我需要将NUMPY数组传递给C++函数,处理它并返回另一个NUMPY数组。,python,c++,arrays,numpy,Python,C++,Arrays,Numpy,现在我已经知道了如何传递和返回数组,但是处理结果的某些步骤并不正确 double * process(double *input, int length) { Map<Matrix<double, 1, Dynamic>> map(input, length); MatrixXd frame(map); ... RowVectorXd b(7); b << 6.46597871e-01, 0.00000000e+00

现在我已经知道了如何传递和返回数组,但是处理结果的某些步骤并不正确

double * process(double *input, int length) {
    Map<Matrix<double, 1, Dynamic>> map(input, length);
    MatrixXd frame(map);
    ...
    RowVectorXd b(7);
    b << 6.46597871e-01,   0.00000000e+00,  -1.93979361e+00,
             1.66081634e-16,   1.93979361e+00,   0.00000000e+00,
            -6.46597871e-01;
    RowVectorXd a(7);
    a <<  1.        , -0.76984955, -1.87432239,  0.90522394,  1.47938621,
               -0.32233495, -0.41804178;

    RowVectorXd temp1 = frame.row(0);
    RowVectorXd temp2 = frame.row(1);
    RowVectorXd first = filter(temp1, a, b);
    ...

}

RowVectorXd filter(RowVectorXd &input, RowVectorXd &alpha, RowVectorXd &beta) {
    float a0 = alpha(0);
    int order = beta.cols();
    RowVectorXd a = alpha.segment(1, order - 1).reverse() / a0;
    RowVectorXd b = beta.reverse() / a0;
    int size = input.size();
    RowVectorXd output(size + (order - 2) * 2);

    RowVectorXd joined = addZeros(input, order - 1);
    size = joined.cols() - (order - 2);

    for (int k = order; k < size ; k++) {
        RowVectorXd x = joined.segment(k - order, order);
        RowVectorXd y = output.segment(k - order, order - 1);
        double temp = b.dot(x) - a.dot(y);
        cout << " " << temp;
        output(k - 1) = b.dot(x) - a.dot(y);
    }
    return output.segment(order - 1, input.cols());
}
这就是版本编译选项

-std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 -fPIC
-std=c++0x -O3 -Wall -c -fmessage-length=0 -march=core2 -ffast-math -fPIC
我想当点积计算时,问题可能是内存对齐或类似的,但这只是一个想法


有人指出我这里有什么问题吗?< /P> < P>好,问题是用未初始化的向量输出,当C++调用时包含零,从Python调用时随机填充。< /P>