[Numpy-discussion] how to work with numpy.int8 in c

David Cournapeau cournape@gmail....
Mon Mar 1 00:44:31 CST 2010


On Mon, Mar 1, 2010 at 1:35 PM, James Bergstra
<bergstrj@iro.umontreal.ca> wrote:
> Could someone point me to documentation (or even numpy src) that shows
> how to allocate a numpy.int8 in C, or check to see if a PyObject is a
> numpy.int8?

In numpy, the type is described in the dtype type object, so you
should create the appropriate PyArray_Descr when creating an array.
The exact procedure depends on how you create the array, but a simple
way to create arrays is PyArray_SimpleNew, where you don't need to
create your own dtype, and just pass the correponding typenum (C
enum), something like PyArray_SimpleNew(nd, dims, NPY_INT8).

If you need to create from a function which only takes PyArray_Descr,
you can easily create a simple descriptor object from the enum using
PyArray_DescrFromType.

You can see examples in numpy/core/src/multiarray/ctors.c

cheers,

David


More information about the NumPy-Discussion mailing list