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

Leo Breebaart leo at lspace.org
Wed Nov 19 02:28:02 CST 2003

Todd Miller wrote:

> Leo Breebaart wrote:
> > [...]
> >        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. [...]
> > Is there somebody who knows what is going or what I am doing
> > wrong?
> Yes and no.   You're in an area that numarray supports differently than
> Numeric.  numarray's support for character arrays is in the Python
> numarray.strings module.  There's no direct support for using it from
> C.

Thanks for the response, Todd.

Do I understand correctly that you are saying it's no longer
possible in numarray (as opposed to Numeric) to create *any* kind
of PyObject array? (After all, the fact that the PyObjects in the
above example are really strings is basically accidental -- what
if I had an array of pointers to e.g. PyLists or PyDicts that I
wanted to store in a numarray -- in Numeric that would also be
possible using the PyArray_OBJECT type, right?)

Am I also correct in thinking that at this point the only
solution to my problem is to manually convert the string arrays
in my data to direct Python lists of strings -- or is there
perhaps some other trick by which I could get them into a
numarray after all? I do a certain amount of Python-level
'post-processing' in my code anyway, and the string arrays I
encounter are expected to have only a few elements each, so it
would be no problem to do some munging after the fact, if that
could help matters.

Leo Breebaart  <leo at lspace.org>

More information about the Numpy-discussion mailing list