[Numpy-discussion] Question about typenum

Richard Hattersley rhattersley at gmail.com
Tue Oct 8 14:51:22 EDT 2013

Hi Valentin,

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.

Richard Hattersley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131008/fa0a98a8/attachment.html>

More information about the NumPy-Discussion mailing list