The function
PyObject* PyArray_TypeObjectFromType(int);
converts the type number for a NumPy scalar type (NPY_BOOL, NPY_BYTE, ...) to the corresponding type object.
How do you do the opposite conversion, from the type object for a NumPy scalar type to the corresponding type number?
Edit: The following code is based on kwatford's answer. It accepts both type objects such as int and numpy.int16, and strings such as "int", u"int" and "int16".
int numpyScalarTypeNumber(PyObject* obj)
{
PyArray_Descr* dtype;
if(!PyArray_DescrConverter(obj, &dtype)) return NPY_NOTYPE;
int typeNum = dtype->type_num;
Py_DECREF(dtype);
return typeNum;
}