I'm passing Numpy data to a C++ extension function using PyArg_ParseTuple.
One of the arguments is a Numpy array of objects, i.e. dtype='O'.
These objects are in fact 1 dimensional Numpy arrays themselves, but each with a different length.
I've succeeded with the following code, but as a novice at building python extensions, I wonder if there is a better way to do this?
PyArrayObject *arr_neighbors=NULL;
PyArg_ParseTuple(args, "O!", &PyArray_Type, &arr_neighbors);
std::vector<long*> neighbors(n_polys);
std::vector<int> neighbor_lengths(n_polys);
for (long i = 0; i < n_polys; i++ ) {
PyObject *array = PyArray_GETITEM(arr_neighbors, PyArray_GetPtr(arr_neighbors, &i));
neighbor_lengths[i] = PyArray_DIM(array, 0);
neighbors[i] = (long*) PyArray_DATA((PyArrayObject*) array);
}