我将新的C++代码嵌入到Python中。我在测试编织.inline. 但是我在运行代码时遇到了一个分段错误。我能告诉我我做错了什么?这是我的代码:
from scipy import weave
def cpp_call(np_points):
assert(type(np_points) == type(1))
code = """
double z[np_points+1][np_points+1];
for (int x = 0; x <= np_points; x++)
{
for (int y = 0; y <= np_points; y++)
{
z[x][y] = x*y;
}
}
"""
return weave.inline(code,'np_points')
我在这里看到两个问题:
1)缩进-您的python函数需要缩进超过
def
行2)你对
weave.inline()
的参数应该是一个列表。见here for details因此,更正后的代码应该如下所示:
这段代码对我来说运行得很好。在
相关问题 更多 >
编程相关推荐