假设我有以下用C编写的函数:
/* C-Code for calculating the average for a given dataset */
#define NOE 16
int calcAvg(float *data, float *avg)
{
float sum; sum = 0;
int i;
for (i = 0; i < NOE; i++)
{
data[i] = i;
sum += data[i];
}
avg = sum/n;
return 0;
}
现在我想将数据从np.array传递给那个C函数“calAvg”。另外,我希望结果存储在我在python中定义的“result”中。
# Python Code
result = float(0)
a = np.array([1, 2, 3, 4])
myCfuncion.calc(a, result)
我已经创建了一个C模块并将其导入到python中。我遇到的问题是我不知道如何以我展示的方式传递指针。
有人有想法吗?