![](/img/trans.png)
[英]How to convert numpy arrays to vector<int>& (reference) with SWIG
[英]Several numpy arrays with SWIG
我使用SWIG将numpy数组从Python传递到C ++代码:
%include "numpy.i"
%init %{
import_array();
%}
%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data, int n)};
class Class
{
public:
void test(float* data, int n)
{
//...
}
};
在Python中:
c = Class()
a = zeros(5)
c.test(a)
这有效,但是如何将多个numpy数组传递给同一个函数?
我找到了我的同事的答案:
%apply (float* INPLACE_ARRAY1, int DIM1) {(float* data1, int n1), (float* data2, int n2)};
class Class
{
public:
void test(float* data1, int n1, float* data2, int n2)
{
//...
}
};
现在将两个numpy数组传递给Class :: test。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.