tianjiaozilong
tianjiaozilong
2021-01-25 19:59

请问各位老师,这个代码怎么解

10
  • python
def getState(data, t, n):
    d = t - n + 1
    # block = data[d:t + 1] if d>= 0 else -d * [data[0]]+ data[0:t+1]
    block = data[d:t + 1]
    res = [0 for x in range(0, n)]
    #res = []
    for i in range(n - 1):
        print("res=",res[i])
        res.append(block[i + 1]-block[i])
        #print("res=",res[i])
        return np.array([res])
    #return np.array([res])

 

File "C:/Users/86138/Desktop/stockPrediction-master/yunfuzai_main.py", line 79, in getState
    res.append(block[i + 1]-block[i])
IndexError: list index out of range
我原先就想解决过界问题,所以我加了

res = [0 for x in range(0, n)],结果还是过界了,想问问怎么解决呢

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

7条回答

为你推荐