【问题标题】:Python interpolation between two large data arrays两个大型数据数组之间的 Python 插值
【发布时间】:2021-11-13 10:32:54
【问题描述】:

我有两个不同年份的数据集(2015 年和 2024 年),需要对 2019 年进行插值。问题是这些数据集的大小;在导入它们并修剪掉不必要的数据列之后,每年的每个一维数组仍然超过 4M 点长。我需要使用 2019 年的插值点创建一个新数组,但到目前为止,我尝试的似乎需要很长时间(测试 200 个数据点大约需要 25 秒)。如何加快速度?

#import data already done, trimming off unnecessary (Location1,Location2) columns.
JT_2015 = np.delete(data_2015,[0,1],1)
JT_2024 = np.delete(data_2024,[0,1],1)

#creating empty array to append interpolated data in to.
JT_2019 = np.array([])

#separate Location1,Location2 set to attach interpolated data to later
nodeSets = np.delete(data_2024,[2],1)

#flattening to 1D arrays
JT_2015 = np.ravel(JT_2015)
JT_2024 = np.ravel(JT_2024)

#loop to interpolate all data points
for i in range(0,len(JT_2015)):
    a = JT_2015[i]
    b = JT_2024[i]
    calc = np.interp(2019,[2015,2024],[a,b])
    JT_2019 = np.append(JT_2019,calc)
    

【问题讨论】:

    标签: python arrays numpy


    【解决方案1】:

    当您只有两个点(2015 和 2024)时,您会被 linear interpolation 卡住。所以你还不如直接做:

    JT_2019 = JT_2015 * ((2024-2019)/(2024-2015)) + JT_2024 * ((2019-2015)/(2024-2015))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-01
      • 2016-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 2014-08-28
      相关资源
      最近更新 更多