我对Python非常陌生。我有一些R中的代码,我正试图用Python重写,我遇到了一个我似乎找不到答案的问题-抱歉,如果这个问题已经得到了答案,或者答案很明显,我已经搜索了,无法修复我的问题
我有一个“高度”列表,它是来自电子表格的481个数字的一列。我希望使用hrc,一个从最小高度值到最大高度值的列表,长度与高度列表相同,但所有值间隔相等。对于hrc中的每个值,我希望通过以下代码运行它,但我得到Indexerror:list index超出范围
hrc = np.linspace(min(height),max(height),len(height))
Qrc = []
for i in range(0,len(hrc)):
if(hrc[i]<0.685):
Qrc.append(30.69*((hrc[i]-0.156)**1.115))
elif(0.685<=hrc[i] and hrc[i]<1.917):
Qrc.append(27.884*((hrc[i]-0.028)**1.462))
elif(1.917<=hrc[i]):
Qrc.append(30.127*((hrc[i]-0.153)**1.502))
谢谢你的帮助
不要索引到列表中(如果不需要的话)-迭代它的值
检查你的
if
条件,你可以简化它们-如果一个较低的范围合适,下一个范围不需要检查现在的值是否比较低的范围大(如果是,你现在就不会检查该范围):输出:
相关问题 更多 >
编程相关推荐