如何在C模块中使用python API访问数组数组
我需要访问从python传递到C模块的数组数组。例如,假设在python中创建了一个数组“A”,如下所示:如何在C模块中使用python API访问数组数组,python,c,arrays,Python,C,Arrays,我需要访问从python传递到C模块的数组数组。例如,假设在python中创建了一个数组“A”,如下所示: from numpy import * from numpy.random import rand from geoms import * A=empty((1,2),dtype=object) A[0,0]=rand(3,3) A[0,1]=rand(5,5) gm_unique_all(A) 其中geoms是C模块,在python中设置并导入,gm_unique_all是一种方法。
from numpy import *
from numpy.random import rand
from geoms import *
A=empty((1,2),dtype=object)
A[0,0]=rand(3,3)
A[0,1]=rand(5,5)
gm_unique_all(A)
其中geoms是C模块,在python中设置并导入,gm_unique_all是一种方法。
我不知道如何通过python API for C访问输入数组“A”的每个子数组。如果大家都能帮助我,我将不胜感激。大概是这样做的:
void processMatrix(PyObject *mat) {
Py_ssize_t r, c;
if (!PySequence_Check(mat))
; // mat is not a sequence
for (r=0; r<PySequence_Length(mat); ++r) {
PyObject *row = PySequence_GetItem(mat, r);
if (!PySequence_Check(row))
; // row is not a sequence
for (c=0; c<PySequence_Length(row); ++c) {
PyObject *obj = PySequence_GetItem(row, c);
// process obj
}
}
}
void processMatrix(PyObject*mat){
Py_ssize_t r,c;
如果(!PySequence_Check(mat))
;//mat不是一个序列
对于(r=0;r