AttributeError:'list'对象没有属性'shape'?

问题描述 投票:0回答:1

有人可以帮我,我一直在尝试运行下面的脚本

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

但仅会出现这样的错误

AttributeError Traceback (most recent call last)<ipython-input-48-9880c2146f81> in <module>()----> 1 X_train = np.reshape(X_train, newshape = (X_train.shape[0], X_train.shape[1], 1))
AttributeError: 'list' object has no attribute 'shape'

这是完整的脚本

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

downloads = pd.read_csv('Datatraining.csv')
training_set = downloads.iloc[:, 1:2].values

from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range = (0, 1))
training_set_scaled = sc.fit_transform(training_set)

X_train = []
y_train = []
for i in range(72, len(training_set_scaled)):
    X_train.append(training_set_scaled[i-60: i, 0])
    y_train.append(training_set_scaled[i, 0])
    X_train, y_train = np.array(X_train), np.array(y_train)

X_train = np.reshape(X_train, newshape = (X_train.shape[0], X_train.shape[1], 1))
python lstm prediction
1个回答
1
投票

您的X_train不是np数组,而是list。您首先必须将列表转换为numpy数组

X_train = np.asarray(X_train)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.