Accessing view of a NumPy array using the C API
In a Python extension module I've written in C++, I use the following snippet of code to convert a NumPy array into an Armadillo array for use in the C++ portion of the code: static arma::mat convertPyArrayToArma(PyArrayObject* pyarr, int nrows, int ncols) { // Check if the dimensions are what I expect. if (!checkPyArrayDimensions(pyarr, nrows, ncols)) throw WrongDimensions(); const std::vector<int> dims = getPyArrayDimensions(pyarr); // Gets the dimensions using the API PyArray_Descr* reqDescr = PyArray_DescrFromType(NPY_DOUBLE); if (reqDescr == NULL) throw std::bad_alloc(); // Convert the