From Python sequence to NumPy array

Turn any relevant Python sequence type (list, type, array) into a NumPy array:
PyObject * PyArray_ContiguousFromObject(PyObject *object,
                                        int item_type,
                                        int min_dim,
                                        int max_dim);
Use min_dim and max_dim as 0 to preserve the original dimensions of object
Application: ensure that an object is a NumPy array,
/* a_ is a PyObject pointer, representing a sequence 
   (NumPy array or list or tuple) */
PyArrayObject a;
a = (PyArrayObject *) PyArray_ContiguousFromObject(a_,
                      PyArray_DOUBLE, 0, 0);
a list, tuple or NumPy array a is now a NumPy array

previousnexttable of contents