Hi,
I have a quick question about typenum. Certain functions, like
`PyArray_SimpleNewFromData` `PyArray_SimpleNew` take a typeenum
argument. Is there any way to go from typeenum to something that can be
passed to the dtype constructor, like mapping 12 -> '
Hi Valentin,
On 8 October 2013 13:23, Valentin Haenel
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 -> '
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 '
Hi Richard,
* Richard Hattersley
On 8 October 2013 13:23, Valentin Haenel
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 -> '
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 '
Thanks for your answer. I ended up using: PyArray_TypeObjectFromType from cython so: np.dtype(cnp.PyArray_TypeObjectFromType(self.ndtype)).str Maybe i can avoid the np.dtype call, when using PyArray_Descr? best, V-
On 8 October 2013 19:56, Valentin Haenel
I ended up using: PyArray_TypeObjectFromType from cython so:
np.dtype(cnp.PyArray_TypeObjectFromType(self.ndtype)).str
Maybe i can avoid the np.dtype call, when using PyArray_Descr?
In short: yes. `PyArray_TypeObjectFromType` first uses `PyArray_DescrFromType` to figure out the dtype from the type number, and then it returns the corresponding array scalar type. Passing this array scalar type to `np.dtype` gets you back to the dtype that had just been looked up inside TypeObjectFromType. Regards, Richard
* Richard Hattersley
On 8 October 2013 19:56, Valentin Haenel
wrote: I ended up using: PyArray_TypeObjectFromType from cython so:
np.dtype(cnp.PyArray_TypeObjectFromType(self.ndtype)).str
Maybe i can avoid the np.dtype call, when using PyArray_Descr?
In short: yes.
`PyArray_TypeObjectFromType` first uses `PyArray_DescrFromType` to figure out the dtype from the type number, and then it returns the corresponding array scalar type. Passing this array scalar type to `np.dtype` gets you back to the dtype that had just been looked up inside TypeObjectFromType.
Excellent! Thank you very much! V-
participants (2)
-
Richard Hattersley
-
Valentin Haenel