I have noticed that it is possible to create a borrowed/stolen reference to a (3D) numpy array of floats using PyArray_AsCArray
as following:
...
float ***matrix_c;
npy_intp dims[3] = {X, Y, Z};
PyArray_Descr *descriptor = PyArray_DescrFromType(NPY_FLOAT32);
PyArray_AsCArray(&matrix_pyobject, (void **)&matrix_c, dims, 3, descriptor);
...
However, when doing this from different parts in the code with the intention of transferring the same array, this will not work for my case. I needed each of the transfers to give me a reference to the inner array, so I could work with the same addresses.
For this purpose I found out I could access the internal array without worrying about references using PyArray_DATA
, nonetheless this gives a 1D flat view of the matrix as a void *
referencing the first element of the matrix.
Is there any way in which I can get a reference to the internal array using this last call and still be able to work with the array as a 3D C array?