[Numpy-discussion] ndarray of object dtype

Robert Kern robert.kern at gmail.com
Thu Oct 7 20:24:16 EDT 2010


On Thu, Oct 7, 2010 at 10:09, Ioan Ferencik <ioan.ferencik at tkk.fi> wrote:
> Hello Robert,
>
> I dare to bother you again with some  questions.
>
> this time I have a numpy array with fields
> ar = array([(1.0, 2.0, 3, 4), (2.0, 3.0, 4, 5)], dtype={'names':
> ['q','wl','cssid','br'], 'formats':['f4', 'f4', 'i4', 'i4'],
> 'offsets': [0, 4, 8, 12]}, order='F')
>
> on C API I want to match this struct
> typedef struct val1{
>        float q;
>        float wl;
>        int cssid;
>        int br;
> }hm1dval1;
>
> to an element of this array
> I get the array object, i can see the fields. The type of the array
> elements is Pyarray_VOID
>
> however following code gives me a segfault
>
> hm1dval1 **s = PyArray_DATA(ao);

Since this is *not* an object array but an array of hm1dval1 structs,
you declare it like so:

hm1dval1 *s = PyArray_DATA(ao);

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list