【发布时间】:2015-05-29 02:44:47
【问题描述】:
我有一个代码,使用roll method of Numpy 为偏微分方程的finite differences 积分方法实现二维拉普拉斯算子:
def lapOp(u):
"""
This is the laplacian operator on 2D array
of stencil of 4th accuracy terms
"""
lap = ((4.0/3.0)*np.roll(u,1,axis=0) + (4.0/3.0)*np.roll(u,-1,axis=0) + (4.0/3.0)*np.roll(u,1,axis=1) + (4.0/3.0)*np.roll(u,-1,axis=1) -5.0*u)
lap -= ((1.0/12.0)*np.roll(u,2,axis=0) + (1.0/12.0)*np.roll(u,-2,axis=0) + (1.0/12.0)*np.roll(u,2,axis=1) + (1.0/12.0)*np.roll(u,-2,axis=1))
lap = lap / hh
return lap
我想对我的代码进行 cythonize - roll 方法可以在我的 pyx 代码中工作,还是应该使用 C 实现 roll 方法?
【问题讨论】:
标签: python python-2.7 numpy cython