python - 为什么我会使用 tf.concat 而不是 tf.stack?

标签 python tensorflow

使用 tf.concat 而不是 tf.stack 有充分的理由吗?它们看起来非常相似。是否只是为了保证生成的张量与输入的张量列表具有相同的维数?

最佳答案

实际上,我误解了tf.stack 的工作原理。如果 axis 参数在现有维度的范围内,将在该索引处插入一个新轴。

例子:

import tensorflow as tf

t1 = tf.random_normal([1, 3])
t2 = tf.random_normal([1, 3])

tf.stack([t1, t2], axis=1).shape.as_list() == [1, 2, 3]
tf.concat([t1, t2], axis=1).shape.as_list() == [1, 6]

关于python - 为什么我会使用 tf.concat 而不是 tf.stack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41534593/

相关文章:

python - 使用 Merge 反透视 Pandas 数据集

python - 将 Tensorflow 编写的损失函数移植到 Keras 会导致 AttributeError

tensorflow - 几个时期后损失开始跳跃

android - Tensorflow Android 库要求 READ_PHONE_STATE?

python - 在量化之前将值反量化为原始值

python - 计算嵌套列表中的频率

python - 我的实时搜索实现是否滥用 PyQt5 方法?

python - 在 TensorFlow 中索引子张量

python - Python 请求在这里做错了什么,还是我的 POST 请求缺少某些东西?

python - 禁用所有子记录器