Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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深度学习Keras:维数错误:预期为3,形状为2 我是Keras,深度学习lib库,需要你的帮助。生成的模型没有错误,但在调用model.fit(X,y)时存在以下问题:_Python_Keras - Fatal编程技术网

Python深度学习Keras:维数错误:预期为3,形状为2 我是Keras,深度学习lib库,需要你的帮助。生成的模型没有错误,但在调用model.fit(X,y)时存在以下问题:

Python深度学习Keras:维数错误:预期为3,形状为2 我是Keras,深度学习lib库,需要你的帮助。生成的模型没有错误,但在调用model.fit(X,y)时存在以下问题:,python,keras,Python,Keras,这个和这个相似 我的y列矩阵是一个包含多行和一列的矩阵 其中一个解决方案是使用二进制1热编码将y转换为3d张量。有这样的例子吗?你在找这样的东西吗 >b=np.arange(640) >b.reshape(16,40).shape (16, 40) >c=b.reshape(1,16,40) >c.shape (1, 16, 40) 您可以使用: from keras.utils import np_utils np_utils.to_categorical(y_t

这个和这个相似 我的y列矩阵是一个包含多行和一列的矩阵


其中一个解决方案是使用二进制1热编码将y转换为3d张量。有这样的例子吗?

你在找这样的东西吗

>b=np.arange(640)
>b.reshape(16,40).shape
 (16, 40)
>c=b.reshape(1,16,40)
>c.shape
 (1, 16, 40)
您可以使用:

from keras.utils import np_utils
np_utils.to_categorical(y_train, n_classes)
对于一个热编码,其中y_列是一个列类向量,n_类是一个类的总数


但是,基于错误描述中提到的是(16,40),而不是(Nx1),我怀疑您的X也可能有问题。

您能提供您的网络架构吗?
from keras.utils import np_utils
np_utils.to_categorical(y_train, n_classes)