- 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
MXNet reshape操作(-1/-2/-3/-4)含义记录
最新推荐文章于 2023-04-06 21:43:27 发布