Tensorflow 张量流-张量整形

Tensorflow 张量流-张量整形,tensorflow,Tensorflow,我使用的是TensorFlow,我有以下矩阵: U2 = tf.constant([[1,3],[0,1],[1,0]],dtype=tf.float32) [[ 1. 3.] [ 0. 1.] [ 1. 0.]] 重塑该矩阵以产生张量的最简单方法是什么: tf.constant([[[1,1],[0,0],[1,1]],[[3,3],[1,1],[0,0]]],dtype=tf.float32) [[[ 1. 1.] [ 0. 0.] [ 1. 1.]] [[

我使用的是TensorFlow,我有以下矩阵:

U2 = tf.constant([[1,3],[0,1],[1,0]],dtype=tf.float32)

[[ 1.  3.]
 [ 0.  1.]
 [ 1.  0.]]
重塑该矩阵以产生张量的最简单方法是什么:

tf.constant([[[1,1],[0,0],[1,1]],[[3,3],[1,1],[0,0]]],dtype=tf.float32)

[[[ 1.  1.]
  [ 0.  0.]
  [ 1.  1.]]

 [[ 3.  3.]
  [ 1.  1.]
  [ 0.  0.]]]

这是使用TensorFlow API创建第一个子矩阵的一种快速方法:

U2 = tf.constant([[1,3],[0,1],[1,0]],dtype=tf.float32)
first_col = tf.unpack(U2, axis=1)[0]
repeated_cols = tf.tile(first_col, [2])
repeated_cols = tf.reshape(repeated_cols, [3,2])
这将创造

[[ 1.  1.]
  [ 0.  0.]
  [ 1.  1.]]