【问题标题】:Curve fitting and Extrapolation for 3d plot in pythonpython中3d图的曲线拟合和外推
【发布时间】:2016-04-26 02:00:38
【问题描述】:

我想使用 numpy/scipy 在 python 中推断 3d 图。外推是通过曲线拟合完成的。请参阅以下具有不同 x 和 y 大小的数据。

x = np.array([740,760,780,800,820,840,860,880,900,920,940,960])     # Presssure in mBar

y = np.array([1500,1800,2100,2400,2700,3000,3300,3600,3900])     # Rpm

# Fuel Amount in micro seconds

z = np.array([[1820,1820,1820,1820,2350,2820,3200,3440,3520,3600,3600,3600],  
              [1930,1930,1930,2170,2700,2880,3240,3580,3990,3990,3990,3990],  
              [1900,1900,2370,2680,2730,3050,3450,3760,3970,3970,3970,3970],  
              [2090,2090,2240,2410,2875,3180,3410,3935,4270,4270,4270,4270],  
              [1600,2180,2400,2700,2950,3290,3780,4180,4470,4470,4470,4470],  
              [2100,2280,2600,2880,3320,3640,4150,4550,4550,4550,4550,4550],  
              [2300,2460,2810,3170,3400,3900,4280,4760,4760,4760,4760,4760],  
              [2170,2740,3030,3250,3600,4100,4370,4370,4370,4370,4370,4370],  
             [2240,2580,2870,3275,3640,4050,4260,4260,4260,4260,4260,4260]])

Scipy 具有 scipy.interpolate.interp2d 类,但它仅在 x 和 y 大小相同时进行插值。 http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html

我想在 y 轴点 900 和 1200 和 x 轴点 720 处外推曲线。

xNew = (720,x)
yNew = (900,1200,y)

因为我没有 z = f(x,y) 的函数。如何在 python 中针对上述情况进行曲线拟合并获取所需点的曲线值。

【问题讨论】:

    标签: python numpy scipy curve-fitting extrapolation


    【解决方案1】:

    您需要提供构建 z 值的网格,即类似

    x=[[740,760,...,960],
       .....
       [740,760,...,960]]
    

    y 也是如此。这可以使用numpy.meshgrid 来实现:

    xx,yy=np.meshgrid(x,y)
    test_function=interp2d(xx,yy,z)
    

    使用您的数据,我可以执行test_function(720,900) 并得到1820 的值,这是最近邻外推。如果您需要“更好”的外推(无论这意味着什么),您需要为您的数据开发某种模型函数并使用 scipy 中的拟合方法。

    【讨论】:

      猜你喜欢
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 2019-02-26
      • 2010-10-09
      • 2020-12-06
      • 2014-11-26
      • 2011-07-07
      相关资源
      最近更新 更多