Python tensorflow合并和压缩两个张量

Python tensorflow合并和压缩两个张量,python,matrix,tensorflow,tensor,Python,Matrix,Tensorflow,Tensor,我有两个张量,如下所示: x1 = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) x2 = tf.constant([[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]) 我应该如何合并和转换x1和x2,这样我就可以有一个张量,如下所示: [[[1.0, 7.0] [2.0, 8.0] [3.0, 9.0]] [[4.0, 10.0] [5.0, 11.0] [6.0, 12.0]] ] 在最后一个轴

我有两个张量,如下所示:

x1 = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
x2 = tf.constant([[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]])
我应该如何合并和转换x1和x2,这样我就可以有一个张量,如下所示:

[[[1.0, 7.0]
  [2.0, 8.0]
  [3.0, 9.0]]

 [[4.0, 10.0]
  [5.0, 11.0]
  [6.0, 12.0]]
]
在最后一个轴上使用:

tf.InteractiveSession()

tf.stack([x1, x2], axis=-1).eval()

#array([[[  1.,   7.],
#        [  2.,   8.],
#        [  3.,   9.]],

#       [[  4.,  10.],
#        [  5.,  11.],
#        [  6.,  12.]]], dtype=float32)