TensorFlow中相关的维度处理函数
1——tf.tile(input, multiples, name=None)
input: 定义好的的张量对象列表;
multiples: 不同维度的复制次数,从第一个维度开始;
name: 此操作的名称(可选)。
a = tf.constant([[1,2],[3,4]],name='a')
输出:
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 2],[3, 4]], dtype=int32)>
b = tf.tile(a,[2,1])
输出:
<tf.Tensor: shape=(4, 2), dtype=int32, numpy=
array([[1, 2],[3, 4],[1, 2],[3, 4]], dtype=int32)>
解释:对a的第一个维度的复制次数是2,对a的第二个维度的复制次数是1。a的第一个维度即为a.shape[0],a的第二个维度即为a.shape[1]。
c = tf.tile(a,[2,3])
输出:
<tf.Tensor: shape=(4, 6), dtype=int32, numpy=
array([[1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4],
[1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4]], dtype=int32)>
解释:对a的第一个维度的复制次数是2,对a的第二个维度的复制次数是3。a的第一个维度即为a.shape[0],a的第二个维度即为a.shape[1]。
2——tf.stack( values, axis=0,name=‘stack’)
value: 具有相同形状和类型的张量对象列表。
axis: 一个整型数。要堆叠的轴。默认为第一个维度。负值环绕,所以有效范围是[-(R+1), R+1)。
name: 此操作的名称(可选)。