【问题标题】:interpolating temperature with height用高度插值温度
【发布时间】:2014-09-17 03:23:39
【问题描述】:

我正在尝试制作一个返回给定高度温度的插值代码

def Fdrag(y):
    alt = [a1, a2, a3,....,an]
    temp = [t1, t2, t3,...., tn]
    for i in range(len(alt)):
        if alt[i] < y < alt[i+1]:
            temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
    return temp

我不断收到此错误:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    Fdrag(10)
  File "C:/Users//Desktop/interp_test.py", line 6, in Fdrag
    temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
TypeError: 'int' object is not subscriptable

【问题讨论】:

    标签: python list int interpolation


    【解决方案1】:

    你说y[i]

            temp = temp[i] + (y - y[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
    

    但我认为你的意思是alt[i]:

            temp = temp[i] + (y - alt[i])*(temp[i+1]-temp[i])/(alt[i+1] - alt[i])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多