提问人:slow_learner 提问时间:2/4/2020 更新时间:2/4/2020 访问量:1381
使用 scipy.interpolate.interp2d 时出现问题。代码执行时间过长
Problem using scipy.interpolate.interp2d. The code takes too long to execute
问:
我有一个包含三列的文本文件。第一个是 X 位置,第二个是 Y 位置,第三个是 X 和 Y 变量的值。我想插值它。但是,当我运行代码时,它花费的时间太长了。在停止执行之前,我已经让它连续运行了 10 分钟,但它没有奏效。我在 mathematica 中构建了一个类似的代码,它只需要 10 秒,就可以做更多的事情。
我读取文本文件并将 X、Y 和 f(X, Y) 的值指定为
f = open('XdataTXT.txt','r')
linesX=f.readlines()
X_column_number = 0
positionX=[]
Y_column_number = 1
positionY=[]
VarX_column_number=2
varX=[]
for x in linesX:
positionX.append(float(x.split()[X_column_number]))
positionY.append(float(x.split()[Y_column_number]))
varX.append(float(x.split()[VarX_column_number]))
f.close()
一旦我有了这三个向量,我就会尝试遵循这个例子,其中做了类似的事情。在那里,分配函数 f(x, y) 的值,然后执行插值。
我的代码如下
windXInterpFunc = interpolate.interp2d(positionX, positionY, windX, kind='cubic')
我也尝试过转置载体,但它也不起作用。
positionXT=np.reshape(positionX, 42441)
positionYT=np.reshape(positionY, 42441)
windXT=np.reshape(windX, 42441)
有人可以告诉我我的错误在哪里吗?
答: 暂无答案
评论
reshape
windXInterpFunc = interpolate.interp2d(positionXT, positionYT, windXT, kind='cubic')
reshape
type
array
numpy.ndarray
windXInterpFunc = interpolate.interp2d(positionXT, positionYT, windXT, kind='RectBivariateSpline')
raise ValueError("Unsupported interpolation type.")
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(positionX, positionY, windX)