swig and c arrays
les ander
les_ander at yahoo.com
Mon Jan 7 21:24:49 EST 2002
Hi,
i am learning how to use swig and having a problem with
arrays.
doubleit.c
-------------
void doubleit(int* arr, int size){
int i;
for (i=0; i< size; i++){
arr[i]=2*arr[i];
}
}
in python :
>>> import doubleit
>>> from Numeric import *
>>> x=array([1,2,3])
>>> x
array([1, 2, 3])
>>> doubleit.doubleit(x,3)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: doubleit, argument 1: expected string, array found
i also tried it with tuple and list,
but i was not able to succeed
>>> doubleit.doubleit('[3 4]',3)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: Type error in argument 1 of doubleit. Expected _int_p.
>>> doubleit.doubleit('[3 4]',3)
can some one please show me how i can pass in and get out
an matrix from a c file.
i would really appreciate if i could get a full example
which uses a 2-d array.
thanks
les
More information about the Python-list
mailing list