使用logspaced点进行2D插值?

时间:2013-10-04 10:30:39

标签: scipy interpolation

我想从大小为NxN的数组中插入一个2d函数。不幸的是,scipy'2dinterpolation返回以下错误:

  

分段错误(核心转储)

即使是下面列出的简化示例:

import scipy as S
import matplotlib.pyplot as plt

from scipy.interpolate import interp2d

def f(x,y):
MaxSum = 8
xTmp   = y/x # trad = y
z      = 0.0 

for n in range(1,MaxSum):
    z    =  z + ( ( S.exp((-1.0*n)*(1.0/y) ) - (1.0/x) ) / (n*x + y) )
return z

f_vec = S.vectorize(f)

N = 128

x = S.logspace(3,8,N) # Note that that I have to use log space for one argument!
                      # I suspect that this is an origin of the problem. 
y = S.linspace(3000,25000,N)

i, j = S.meshgrid(x, y)

z = f_vec(i,j)

plt.figure()
plt.grid(True)
plt.contourf(z)
plt.colorbar()
plt.show()

# Interpolation

f_interpolated = interp2d(x, y, z) # error here 
x_new = S.logspace(3,8,3*N)
y_new = S.linspace(3000,25000,3*N)
z_iterpolated = f_interpolated(x_new, y_new)

plt.figure()
plt.grid(True)
plt.contourf(z_iterpolated)
plt.colorbar()
plt.show()

任何想法我如何调试或如何插入它(我想坚持使用2d线性插值,因为这个scipy脚本只是在Fortran中进一步实现的原型,其中性能将是至关重要的问题)

0 个答案:

没有答案
相关问题