tensorflow维度相关的问题

1、降掉为1的维度

#P => shape=[1,3,3,1]

P1=tf.squeeze(P) #降掉所有为1的维度
P2=tf.squeeze(P, [3]) #降掉指定维度为1的维度

#降维之后的结果
P1 => Tensor("Squeeze:0", shape=(3, 3), dtype=float32)
P2 => Tensor("Squeeze_1:0", shape=(1, 3, 3), dtype=float32)

2、增加维度(一般只能增加为1的维度,并且需要指定哪一维度)

#P => shape=[3,3]

P3=tf.expand_dims(P,0) #
P4=tf.expand_dims(P,2)

#增加维度之后的结果
P3 => Tensor("ExpandDims:0", shape=(1, 3, 3), dtype=float32)
P4 => Tensor("ExpandDims_1:0", shape=(3, 3, 1), dtype=float32)

3、合并维度(需要指定维度,并且合并的两个tensor的shape需要一致)

# P1 => shape[1,3,3]
# P2 => shape[1,3,3]

P_1=tf.concat([P1,P2],axis=0)
P_2=tf.concat([P1,P2],axis=1)
P_3=tf.concat([P1,P2],axis=2)

#维度合并之后的结果,简单看就是维度相加,并不是对应tensor值相加

P_1 => Tensor("concat:0", shape=(2, 3, 3), dtype=float32)
P_2 => Tensor("concat_1:0", shape=(1, 6, 3), dtype=float32)
P_3 => Tensor("concat_2:0", shape=(1, 3, 6), dtype=float32)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值