MXNet reshape操作(-1/-2/-3/-4)含义记录

  • 0起一个占位符的作用,默认从左到右进行占位(除非传入reverse=1,则从右到左),维持原数组在该位置的维度。
    • input shape = (2,3,4), shape = (4,0,2), output shape = (4,3,2) # 中间维度维持不变
    • input shape = (2,3,4), shape = (2,0,0), output shape = (2,3,4) # 后两个维度维持不变
  • -1是最后进行推导的,先保证其他数字被照顾好之后,在reshape前后数组的size不变的约束下,推导出该位置的维度。通常来说,最多只有一个-1,但是在有 -4 的情况下,可以有两个 -1。

    • input shape = (2,3,4), shape = (6,1,-1), output shape = (6,1,4)
    • input shape = (2,3,4), shape = (3,-1,8), output shape = (3,1,8)
    • input shape = (2,3,4), shape=(-1,), output shape = (24,)
  • -2可以包括多个维度。当其他位置都有对应的维度之后,-2就来容纳剩下的多个维度。

    • input shape = (2,3,4), shape = (-2,), output shape = (2,3,4) # -2来容纳所有的维度
    • input shape = (2,3,4), shape = (2,-2), output shape = (2,3,4) # 2占据了一个维度,-2容纳剩下的(3,4)
    • input shape = (2,3,4), shape = (-2,1,1), output shape = (2,3,4,1,1) # (1,1)是新增的两个维度,-2将(2,3,4)给容纳
  • -3是将对应的两个维度合成一个维度,合成之后的维度值为之前两个维度的乘积。

    • input shape = (2,3,4), shape = (-3,4), output shape = (6,4)
    • input shape = (2,3,4,5), shape = (-3,-3), output shape = (6,20)
    • input shape = (2,3,4), shape = (0,-3), output shape = (2,12)
    • input shape = (2,3,4), shape = (-3,-2), output shape = (6,4)
  • -4是将一个维度拆分为两个,-4后面跟两个数字,代表拆分后的维度,其中可以有-1。

    • input shape = (2,3,4), shape = (-4,1,2,-2), output shape =(1,2,3,4) # 将2拆分为1X2,剩下的3,4传递给-2
    • input shape = (2,3,4), shape = (2,-4,-1,3,-2), output shape = (2,1,3,4) # 将3拆分为1X3,剩下的4传递给-2
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值