如何修复错误:数组

时间:2018-03-27 18:13:07

标签: python machine-learning keras lstm

我收到错误" formattedData = run.formatData(temp)" " IndexError:数组"

的索引太多了
   data = np.insert(data,0,scrape())
   data = data.astype(np.float)

   print(data)

   temp = data

   formattedData = run.formatData(temp)

这是引用的函数

def formatData(a):


    sequence_length = 4
    result = []
    for index in range(len(a) - sequence_length):
        result.append(a[index: index + sequence_length])

    result = normalise_windows(result)

    result = np.array(result)

    x = result[:, :-1]
    y = result[:, -1]


    x = np.reshape(x, (x.shape[0], 1, 1))

    return x

这是normalize_window

def normalise_windows(window_data):
    normalised_data = []
    for window in window_data:
        try:
            normalised_window = [((float(p) / float(window[0])) - 1) for p in window]
        except ValueError:
            normalised_window = [((float(p) / float(window[0])) - 1) for p in window]
        normalised_data.append(normalised_window)
    return normalised_data

完整错误堆栈跟踪:

Traceback (most recent call last):
  File "/Users/carson/mlTechnicalAnalysis/autoTrader.py", line 71, in <module>
    scheduler.add_job(main(data), 'cron', hour='9-16', minute='*/5')
  File "/Users/carson/mlTechnicalAnalysis/autoTrader.py", line 54, in main
    formattedData = run.formatData(temp)
IndexError: too many indices for array

我一直试图解决这个问题几个小时,但我无法到达任何地方。我已经尝试使数组浮点数而不是字符串,并完全从我知道在另一组代码上工作的基础上的formatData函数开始。我感谢所有人从我们所有人那里获得的帮助。非常感谢

0 个答案:

没有答案