假设我有一个张量和形状[a,b],另一个张量表示形状[a,c],其中c<b。我想将两者合并为一个张量与维数[a, b+c]。如何在TensorFlow中实现这一点?在这种情况下,仅仅使用tf.concat是行不通的,因为它期望除0以外的所有维度都相等:
All dimensions except 0 must match.
为了清楚地理解tensorflow中的张量,我需要清楚地了解张量是如何定义的。以下是tensorflow文档中的一些例子:
3 # a rank 0 tensor; this is a scalar with shape [] [1. ,2., 3.] # a rank 1 tensormatrix with shape [2, 3] [[[1., 2., 3.]], [[7., 8., 9.]]] # a rank 3 tensor
给定形状为a,n和y的张量x,形状为b,n,函数f(p,q)对形状为1,n的张量进行运算并返回一个标量值,如何在x和y的批量维度上成对地计算f,以便我得到的张量为a,b,1 我知道这适用于这里描述的乘法和加法这样的操作:通过隐式广播的Evaluate all pair combinations of rows of two tensors in tensorflow</em