.reshape()-1或0的含義
x = nd.arange(16)
y = x.reshape(-1, 4)
結果:
[[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.]
[ 8. 9. 10. 11.]
[ 12. 13. 14. 15.]]
<NDArray 4x4 @cpu(0)>
x = nd.arange(16).reshape(-1, 4)
y = x.reshape(0, 1)
結果
[[ 0.]
[ 1.]
[ 2.]
[ 3.]]
<NDArray 4x1 @cpu(0)>
- 如果爲0,保持和原通道數一致
- 如果等於-1的話,那麼根據剩下的維度計算出數組的另外一個shape屬性值。
x.reshape(-1, 4)
也就是說,先前我們不知道x的shape屬性是多少,但是想讓x變成只有四列,行數不知道多少,通過x.reshape(-1,4)
,自動計算出有4行,新的數組shape屬性爲(4, 4)
,與原來配套。