目标是附加 2 个具有一个匹配形状的张量
import tensorflow as tf
x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
res = tf.stack([x, y],axis=0)
print(res)
->tf.Tensor(
[[1 4]
[2 5]], shape=(2, 2), dtype=int32)
print(z)
->tf.Tensor([3 6], shape=(2,), dtype=int32)
result = tf.stack((res, z),axis=1)
->tensorflow.python.framework.errors_impl.InvalidArgumentError: Shapes of all inputs must match: values[0].shape = [2,2] != values[1].shape = [2] [Op:Pack] name: stack
我所期望的
print(result)
->->tf.Tensor(
[[1 4]
[2 5]
[3,6]], shape=(2, 3), dtype=int32)
我尝试了 concat 和 stack 的不同组合。这怎么可能 ?