Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';列表';对象没有属性';形状';?_Python_Lstm_Prediction - Fatal编程技术网

Python 属性错误:';列表';对象没有属性';形状';?

Python 属性错误:';列表';对象没有属性';形状';?,python,lstm,prediction,Python,Lstm,Prediction,有人能帮我吗,我一直在试着运行下面的脚本 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.resha

有人能帮我吗,我一直在试着运行下面的脚本

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'

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

X_train = np.asarray(X_train)

我也有一个类似的错误,我设法解决了它,我把无处不在的
xu列
改成
xu列

xu列
是一个列表,而不是
ndarray
np。asarray(xu列)
np.数组(xu列)有明显的不同
?@alaniwi在这方面有一个很好的思路:asarray效率更高,因为它在不需要的情况下不会复制,而选项更少。在OP问题上,这确实没有什么区别。
X_train = np.asarray(X_train)