python - How to convert numpy ndarray to C float *[] -
i have code in c
, use in python
, used swig wrap c-code, , got python module imported in python code.
now have following code:
import flame import numpy np data = np.random.rand(3,2).astype(np.float32, copy=false) n = 3 m = 2 print data flameobject = flame.flame_new() flame.flame_setdatamatrix( flameobject, data, n, m, 0 )
and gives error:
typeerror: in method 'flame_setdatamatrix', argument 2 of type 'float *[]'
i understand should pass float array pointer
method, how can convert numpy multi-dimensional array correct type?
there scipy documentation on this: how pass numpy arrays c code via swig (and vice versa). have here.
basically, there swig interface file numpy.i
use in following way. in swig interface file include:
%{ #define swig_file_with_init %} %include "numpy.i" %init %{ import_array(); %}
and add in interface file, before mentioning c functions:
%apply ( float* in_array2, int dim1, int dim2 ) { (float* your_array_parameter_name, int n_parameter_name, int m_parameter_name) };
this works ordinary c float
arrays. not quite sure float* []
is. may need write own typemaps this, can use utility macros provided numpy.i
. explained in numpy.i documentation mentioned above, or in relevant swig typemap docs
Comments
Post a Comment