首页 > 解决方案 > 使用 SciPy 进行插值

问题描述

我想使用 Scipy-> interpolate-> interp2d。插值结果是正确的,但为什么结果在列表中保存了三次?我使用了下一个脚本:

from scipy import interpolate import numpy as np

def main(): 
    x = np.array([1, 2, 3, 4])
    y = np.array([1, 2])
    z = np.array([[4,4,6,6],[6, 6,12, 12]])
    f = interpolate.interp2d(x, y, z, kind='linear', copy = False)

    xi = np.array([1.5, 2.5, 3.5])
    yi = np.array([1.5,1.5,1.

结果是:

zi =[[ 5.  7.  9.][ 5.  7.  9.] [ 5.  7.  9.]]

请问你能帮我吗?

标签: pythonscipy

解决方案


Your input arrays x,y,z need to be of identical shape. In your case one has four entries, one has two entries, and the other one is two dimensional with four entries. This will trigger numpy broadcasting. https://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast.html


推荐阅读