[Numpy-discussion] ndarray of object dtype

Ioan Ferencik ioan.ferencik@tkk...
Mon Oct 4 00:41:20 CDT 2010

Hello list,

I am trying to pass elements of a custom defined with C API.
I have successfully wrapped a type around a C struct.
I intent to create a list with these objects and process it using numpy C API.
So i  create an array:

array = (PyArrayObject *)PyArray_ContiguousFromObject(input,  
PyArray_OBJECT, 0, 0);

to my understanding each el. in this array is a pointer to my type so  
a cast to this type
should work.

this is my custom type

typedef struct val{
         float q;
         float wl;
         int cssid;
         int br;

I am passing only one element for testing purposes.

in python
a = [hm1d1.hm1dval() for i in range(0,1)]
for c in a:
         c.set_values(q=3.0, wl=2.5, cssid=6, br=7)

So following code should be valid in C:

hm1dval s* = PyArray_DATA(array);

but the members are 0 after casting in spite they were set previously.

also using strides it should be possible to traverse the array and get  
the individual


Ioan Ferencik
PhD student
Aalto University
School of Science and Technology
Faculty Of Civil and Env. Engineering
Lahti Center
Tel: +358505122707

More information about the NumPy-Discussion mailing list