python - TensorFlow 形状 (?,) 是什么意思?
问题描述
我得到一个 TensofFlow 张量的形状:
(?,)
这个答案说这?
意味着维度在图表中不是固定的,它可以在运行调用之间变化。
?
与尾随逗号结合是什么意思?
文档章节和诗句将不胜感激。我发现语法很难用谷歌搜索。
解决方案
逗号表示维度表示为1-elem 元组而不是 int。
每个张量在创建时默认是一个 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)
但是,您可以重塑它以获得更“完整”的形状(即 n X m / n X m X r...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)
推荐阅读
- python - 如何将 R 中的 fit() 函数翻译成 Python
- swift - 如何在 SwiftUI 中连接多个连续视图
- sql - 发布到 Azure 未创建所有 SQL 表
- gatsby - 在 gatsby 构建期间无法读取样式化组件的主题属性
- python - 训练,神经网络,但为什么 Model.add 不起作用?
- c# - 无法建立 HTTP/2 连接,因为服务器未完成 HTTP/2 握手
- go - 如何在 GORM 中处理递归关联
- jsf - Primefaces 3.4.1 不会在对话框中使用表单进行 POST
- excel - 如何搜索两个不同的范围并输入答案
- css - 如何在 Ant Design 中调整拖动行的高度?