python scipy/weave c.在c.cod中使用python变量

2024-09-27 17:59:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在python中使用inline-from运行一些c代码精纺. 你知道吗

假设我们有2个双数组和onbe双值,我想把第一个索引的每个索引加上下一个索引的对应索引,再加上这个值。你知道吗

C代码:

double* first;
double* second;
double val;
int length;

int i;
for (i = 0; i < length; i++) {
    second[i] = second[i] + first[i] + val;
}

然后我希望在python代码中再次使用“second”数组。你知道吗

给定以下python代码:

import numpy
from scipy import weave

first = zeros(10) #first double array
second = ones(10) #second python array
val = 1.0

code = """
    the c code
"""
second = inline(code,[first, second, val, 10])

如果这是发送阵列/取出阵列的正确方法,以及如何在c代码中使用/访问阵列,那么我就不是舒尔了。你知道吗


Tags: 代码fromimportinlinecodeval数组array

热门问题