Multiple numpy arrays with SWIG

I use SWIG to pass numpy arrays from Python code in 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) { //... } }; 

and in Python:

 c = Class() a = zeros(5) c.test(a) 

This works, but how can I pass multiple numpy arrays into the same function?

+4
source share
1 answer

I found out the answer from my colleague:

 %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) { //... } }; 

Now two numpy arrays are passed to Class :: test.

+9
source

Source: https://habr.com/ru/post/1307436/


All Articles