错误'numpy.ndarray'对象没有属性'append'

时间:2019-08-27 01:25:02

标签: lstm

for i in range(60,1259):
    x_train.append(training_scaled[i-60:i, 0])
    y_train.append(training_scaled[i,0])
x_train,y_train = np.array(x_train),np.array(y_train)

这里1259是行数,在运行LSTM模型之前,我正在进行特征缩放

1 个答案:

答案 0 :(得分:0)

我认为根据官方文档,正确的可能如下:

import numpy as np

for i in range(60,1259):
    np.append(x_train,training_scaled[i-60:i, 0])
    np.append(y_train,training_scaled[i,0])
x_train,y_train = np.array(x_train),np.array(y_train)

编辑 :(在for循环中)

x_train = np.append(x_train,training_scaled[i-60:i, 0])
y_train = np.append(y_train,training_scaled[i,0])

# np.append just returns a copy which must be saved for further changes

因为append()的参数是Arg-1:应附加新值的数组和Arg-2:要附加新值的数组。

供参考,click here