x.shape=[2,3,4]
修改视图
tf.reshape(x,newShape)
增加维度
tf.expand_dims(x,axis)指定axis前插入维度
tf.expand_dims(x,0) 后 x.shape=[1,2,3,4]
删除维度
tf.squeeze(x,axis),只能删除长度为1的维度,不指定axis时删除所有长度为1的维度
tf.squeeze(x,0) 后 x.shape=[2,3,4]
交换维度
tf.transpose(x,perm=)
perm参数为新维度的顺序,list
x.shape=[2,3,4]
tf.transpose(x,perm=[1,2,0])
x.shape=[3,4,2]
复制数据
tf.tile(x,multiples)
multiples与x的shape一致,参数
表示在对应的维度复制的次数,1表示不复制
a = tf.constant([[1,2],[3,4]])
b = tf.tile(a,[2,3])
a
[[1 2 ]
[3 4 ]]
b
[[1 2 1 2 1 2]
[3 4 3 4 3 4]
[1 2 1 2 1 2]
[3 4 3 4 3 4]]