2

サイズ 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()

どのようにデバッグできるか、またはどのように補間できるかについてのアイデア (この scipy スクリプトは、パフォーマンスが重要な問題になる Fortran でのさらなる実装のためのプロトタイプにすぎないため、2D 線形補間に固執したいと思います)

4

0 に答える 0