Tensorflow 如何在输出中使用额外的维度执行tf.tile?

Tensorflow 如何在输出中使用额外的维度执行tf.tile?,tensorflow,Tensorflow,假设我有一个tensor=tf.常数([1,2]),那么创建[[tensor,tensor],[tensor,tensor]]的张量的最佳方法是什么,也就是[[1,2],[1,2],[1,2]]] 用例看起来类似于tf.tile。但是,tf.tile不会创建额外的维度。在使用tile之前重塑张量,此示例演示: import tensorflow as tf sess = tf.InteractiveSession() tensor = tf.constant([1, 2]) tensor_re

假设我有一个
tensor=tf.常数([1,2])
,那么创建
[[tensor,tensor],[tensor,tensor]]
的张量的最佳方法是什么,也就是
[[1,2],[1,2],[1,2]]]


用例看起来类似于
tf.tile
。但是,
tf.tile
不会创建额外的维度。

在使用tile之前重塑张量,此示例演示:

import tensorflow as tf
sess = tf.InteractiveSession()

tensor = tf.constant([1, 2])
tensor_reshaped = tf.reshape(tensor, (1,1,2))
tf.tile(tensor_reshaped, [2, 2, 1]).eval()

Out[22]: 
array([[[1, 2],
        [1, 2]],
       [[1, 2],
        [1, 2]]], dtype=int32)