2

我想从大小为 NxN 的数组中的值插入一个二维函数。不幸的是 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 中进一步实施的原型,其中性能将是关键问题)

4

0 回答 0