Python Array Reshaping Issue to Array with Shape (None, 192)
Posted
技术标签:
【中文标题】Python Array Reshaping Issue to Array with Shape (None, 192)【英文标题】: 【发布时间】:2017-03-01 18:25:08 【问题描述】:我有这个错误,我不知道如何重塑有None
的维度。
Exception: Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)
如何将数组重塑为 (None, 192)?
我有数组accuracy
,形状为(12, 16)
,我做了accuracy.reshape(-1)
,得到(192,)
。然而这不是(None, 192)
。
【问题讨论】:
arr.ravel()[None]
或 arr.reshape(1,-1)
?
Suspiciously similar
@AndrasDeak 感谢您的链接!
所以您需要告诉我们您正在运行哪些模块。显然,numpy
本身并没有发生这种情况。我希望错误是expected (1,192) got ...
; None
(np.newaxis
) 用于创建大小为 1
的维度,但您不会在 shape
元组或错误消息中看到它。但处于开发早期阶段的模块可能仍会使用它。
【参考方案1】:
在keras/keras/engine/training.py
def standardize_input_data(data, names, shapes=None,
check_batch_dim=True,
exception_prefix=''):
...
# check shapes compatibility
if shapes:
for i in range(len(names)):
...
for j, (dim, ref_dim) in enumerate(zip(array.shape, shapes[i])):
if not j and not check_batch_dim:
# skip the first axis
continue
if ref_dim:
if ref_dim != dim:
raise Exception('Error when checking ' + exception_prefix +
': expected ' + names[i] +
' to have shape ' + str(shapes[i]) +
' but got array with shape ' +
str(array.shape))
与错误比较
Error when checking : expected input_1 to have shape (None, 192) but got array with shape (192, 1)
所以它正在比较(None, 192)
和(192, 1)
,并跳过第一个轴;这是比较192
和1
。如果array
的形状为(n, 192)
,它可能会通过。
所以基本上,是什么生成了(192,1)
形状,而不是(1,192)
或可广播的(192,)
导致错误。
我将keras
添加到标签中,猜测这是问题模块。
搜索其他keras
标记的 SO 问题:
Exception: Error when checking model target: expected dense_3 to have shape (None, 1000) but got array with shape (32, 2)
Error: Error when checking model input: expected dense_input_6 to have shape (None, 784) but got array with shape (784L, 1L)
Dimensions not matching in keras LSTM model
Getting shape dimension errors with a simple regression using Keras
Deep autoencoder in Keras converting one dimension to another i
我对@987654340@ 的了解不够多,无法理解答案,但不仅仅是简单地重塑您的输入数组。
【讨论】:
以上是关于Python Array Reshaping Issue to Array with Shape (None, 192)的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode | 0167: Two Sum II - Input array is sortedPython
167. (Two Sum II - Input array is sorted)两数之和 II - 输入有序数组
1961-Check If String Is a Prefix of Array