Creating a descr with aligned=1 using the C API
![](https://secure.gravatar.com/avatar/fa3279b202e9a85f7d90a0422bca4489.jpg?s=120&d=mm&r=g)
Hello all I was wondering what the best way would be to create the following descr using the C API: descr = dtype({'names' : ['index', 'value'], 'formats' : [intc, 'f8']}, align=1) One could use PyArray_DescrConverter in multiarraymodule.c, but there doesn't seem to be a way to specify aligned=1 and one would have to build the dict object before being able to pass it on for conversion. Unless there's another easy way I'm missing, the API could possibly do with a function like PyArray_DescrFromCommaString(const char*, int align) which calls _convert_from_commastring. By the way, what is the general format of these commastrings? Comments appreciated. Regards, Albert
![](https://secure.gravatar.com/avatar/49df8cd4b1b6056c727778925f86147a.jpg?s=120&d=mm&r=g)
Albert Strasheim wrote:
You can use the "new" method. PyArray_Descr *dtype PyObject *dict; dtype = PyArrayDescr_Type.ob_type->tp_new(dtype->ob_type, Py_BuildValue("Oi", dict, 1)); where the dict is the one you give. Yes, this could be an easier-to use API.
It's in the NumPy book and it's also documented by numarray... -Travis
![](https://secure.gravatar.com/avatar/49df8cd4b1b6056c727778925f86147a.jpg?s=120&d=mm&r=g)
Albert Strasheim wrote:
You can use the "new" method. PyArray_Descr *dtype PyObject *dict; dtype = PyArrayDescr_Type.ob_type->tp_new(dtype->ob_type, Py_BuildValue("Oi", dict, 1)); where the dict is the one you give. Yes, this could be an easier-to use API.
It's in the NumPy book and it's also documented by numarray... -Travis
participants (2)
-
Albert Strasheim
-
Travis Oliphant