[Numpy-discussion] Question about typenum

Valentin Haenel valentin at haenel.co
Tue Oct 8 14:56:33 EDT 2013

Hi Richard,

* Richard Hattersley <rhattersley at gmail.com> [2013-10-08]:
> On 8 October 2013 13:23, Valentin Haenel <valentin at haenel.co> wrote:
> > Certain functions, like
> > `PyArray_SimpleNewFromData` `PyArray_SimpleNew` take a typeenum
> > Is there any way to go from typeenum to something that can be
> > passed to the dtype constructor, like mapping 12 -> '<f8'?
> >
> If you just want the corresponding dtype instance (aka PyArray_Descr) then
> `PyArray_DescrFromType` should be what you're after.
> But if you really need the '<f8' string then I'd be tempted to get the
> PyArray_Descr and then use the Python API (e.g. PyObject_GetAttrString) to
> request the "str" attribute. Under the hood this attribute is implemented
> by `arraydescr_protocol_typestr_get` but that's not part of the public API.

Thanks for your answer. I ended up using: PyArray_TypeObjectFromType
from cython so:


Maybe i can avoid the np.dtype call, when using PyArray_Descr?



More information about the NumPy-Discussion mailing list