[Numpy-discussion] (newbie) How can I use NumPy to wrap my C++ class with 2-dimensional arrays?

Raymond de Vries reedev@zonnet...
Thu Jul 30 01:41:44 CDT 2009


Hi everyone,

(I sent this message yesterday as well but somehow it didn't come 
through...)

I would like to ask your advice how I can use NumPy to wrap my existing 
C++ library with 2-dimensional arrays. I am wrapping the library with 
swig and I have the typemap function declaration. But now I am 
struggling a lot to find an implementation for getting access to the 
2-dimensional arrays in my C++ classes. I have wrapped most of the 
library but the multi-dimensional arrays are problematic. From what I 
have read, I can use NumPy for this..

There is so much information about NumPy, Numeric etc that it is not 
clear anymore which example I can use best. It's clear that NumPy is 
probably the way to go.

This is a small example of the class that I would like to wrap:
struct MyClass {
 float array1[2][2];
 std::vector<float> array2[2];
};

I've also read that I need to call import_array() but where should I put 
this?

Is there a small example with NumPy c-api to wrap/convert my 
2-dimensional arrays to python?

Thanks a lot already
Raymond


More information about the NumPy-Discussion mailing list