I have a main program written in C and would like to use an already written library in Python, so I embedded some C-Python API into my C program.
I have successfully created a PyObject that represents a numpy array, containing float data in C, and sent it as an argument to a function defined inside a Python script, which will be called by the C program via the following command:
pValue = PyObject_CallObject(pFunc, pArgs);,
where the pFunc
is the name of the function to be called in the Python script, pArgs
is a PyObject containing arguments to be passed to the function, and pValue
is of type PyObject
which I believe that it will contain the returned result.
The function inside the Python script processes the sent array and then returns a 2-dimensional numpy array of shape (nrow, ncol)
, containing float data, to my main C program.
How can I retrieve the data inside the returned array, and copy them to a C array?
There is an example in https://docs.python.org/3/extending/embedding.html#pure-embedding showing how to retrieve a long value by using
int d = PyLong_AsLong(pValue));
But, what's about a numpy array? Is there something like PyArray_AsCArray() that can be used?