[Numpy-discussion] Problems creating a numarray of type PyArray_OBJECT

Leo Breebaart leo at lspace.org
Tue Nov 18 10:40:10 CST 2003

Hi all,

Using the numarray C API, I am trying to create an array
containing Python strings from an existing C (char **) array.

In Numeric 23.1, the following code fragment works fine:

   PyObject *pdata = NULL;
       // num_elements has been defined earlier
   PyStringObject **strarray = malloc(num_elements * sizeof(PyStringObject *));
   if (strarray != NULL)
       int e;
       for (e = 0; e < num_elements; e++)
           strarray[e] = (PyStringObject *) PyString_FromString(((char **)data)[e]);
          // num_dims and the dim array have been defined earlier
       pdata = PyArray_FromDimsAndData(num_dims, dim, PyArray_OBJECT, 
                                       (char *)strarray);

In numarray 0.7, the same code yields the runtime error:

   libnumarray.error: Type object lookup returned NULL for type 14

in the PyArray_FromDimsAndData() call.

Using the current numarray CVS head instead of the 0.7 release
makes no difference.

Is there somebody who knows what is going or what I am doing

Many thanks in advance,

Leo Breebaart  <leo at lspace.org>

More information about the Numpy-discussion mailing list