Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TensorFlow-3D张量,从2D张量和步长1中收集每N个张量_Python_Tensorflow_Slice_Reshape - Fatal编程技术网

Python TensorFlow-3D张量,从2D张量和步长1中收集每N个张量

Python TensorFlow-3D张量,从2D张量和步长1中收集每N个张量,python,tensorflow,slice,reshape,Python,Tensorflow,Slice,Reshape,假设我在[M,1]中有一个2D张量T T = tf.expand_dims([A1, B1, C1, A2, B2, C2], 1) 我想把它改造成这样: T_reshp = [[[A1], [A2]] [[B1], [B2]] [[C1], [C2]]] 我事先知道M和N(每组张量的数量)。此外,在我尝试使用的tf.reshape T_reshp = tf.reshape(T, [P, N, 1]

假设我在
[M,1]
中有一个
2D张量
T

T = tf.expand_dims([A1,
     B1,
     C1,
     A2,
     B2,
     C2], 1)
我想把它改造成这样:

T_reshp = [[[A1], [A2]]
           [[B1], [B2]]
           [[C1], [C2]]]
我事先知道
M
N
(每组张量的数量)。此外,在我尝试使用的
tf.reshape

T_reshp = tf.reshape(T, [P, N, 1])
然而,我最终得出以下结论:

T_reshp = [[[A1], [B1]]
           [[C1], [A2]]
           [[B2], [C2]]]

我可以使用一些切片或整形操作来进行此操作吗?

您可以先将其整形为尺寸
[N,p,1]
,然后
转置第一和第二轴:

tf.transpose(tf.reshape(T, [N, P, 1]), [1,0,2])
#                           ^^^^ switch the two dimensions here and then transpose

例如:


您可以先将其重塑为尺寸
[N,p,1]
,然后
转置第一和第二轴:

tf.transpose(tf.reshape(T, [N, P, 1]), [1,0,2])
#                           ^^^^ switch the two dimensions here and then transpose

例如:


优雅的解决方案!优雅的解决方案!