使用Puthon Tensorflow输入形状(53,))...这个逗号是怎么回事?

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

我对以下代码行感到困惑:

input_img = Input(shape=(53,))

我有52张图像,但是元组在逗号后怎么可能什么都没有?这是什么意思?

python python-3.x tensorflow keras keras-layer
2个回答
0
投票

与标量相同,但被解释为形状。

如果您感到困惑,您也可以查看列表如何滥用它,例如:

print([
       0,
       1,
       2,
])

[0,1,2]


0
投票

函数输入,参数shape的元组除外

使用逗号可以定义具有唯一值的元组。如果仅使用(53)或53,它将被解释为整数:

type( 53 )
<class 'int'>
type( (53) )
<class 'int'>
type( (53,) )
<class 'tuple'>

这是因为在计算中使用了简单的括号,因此无法将其解析为元组:

(53) + 2 # would raise an error if (53) was a tuple
(53 + 1)*2 # would also raise an error if (53+1) was a tuple
© www.soinside.com 2019 - 2024. All rights reserved.