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

James Bergstra bergstrj@iro.umontreal...
Tue Mar 2 13:44:00 CST 2010

On Mon, Mar 1, 2010 at 1:44 AM, David Cournapeau <cournape@gmail.com> wrote:
> 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

Maybe I'm missing something... but I don't think I want to create an array.

In [3]: import numpy

In [4]: type(numpy.int8())
Out[4]: <type 'numpy.int8'>

In [5]: isinstance(numpy.int8(), numpy.ndarray)
Out[5]: False

I want to create one of those numpy.int8 guys.  Can I do it with
PyArray_XXX methods?


More information about the NumPy-Discussion mailing list