使用 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/