且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

TensorFlow 形状 (?,) 是什么意思?

更新时间:2023-12-02 08:41:16

逗号表示维度表示为 1-elem 元组而不是 int.

The comma means that the dimension is represented as a 1-elem tuple instead an int.

每个张量在创建时默认是一个 n-dim:

Each tensor, when created, is by default a n-dim:

import tensorflow as tf
t = tf.constant([1, 1, 1])
s = tf.constant([[1, 1, 1],[2,2,2]])

print("0) ", tf.shape(t))
print("1) ", tf.shape(s))

0)  Tensor("Shape_28:0", shape=(1,), dtype=int32)
1)  Tensor("Shape_29:0", shape=(2,), dtype=int32)

但是,您可以将其重塑为更完整"的形状(即 nXm/nXmXr...昏暗):

However, you can reshape it to get a more "whole" shape (i.e. nXm / nXmXr... dim):

print("2) ", tf.reshape(t, [3,1]))
print("3) ", tf.reshape(s, [2,3]))

2)  Tensor("Reshape_12:0", shape=(3, 1), dtype=int32)
3)  Tensor("Reshape_13:0", shape=(2, 3), dtype=int32)