# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.arange(0a,12).reshape(4,3)print xy = x.reshape(3,0)print yy = x.reshape(0,3)print yy = x.reshape(0,2)print yy = x.reshape(0)print y
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[0. 1. 2.]
[3. 4. 5.]
[6. 7. 8.]]
<NDArray 3x3 @cpu(0)>
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[0. 1.]
[2. 3.]
[4. 5.]
[6. 7.]]
<NDArray 4x2 @cpu(0)>
[0. 1. 2. 3.]
<NDArray 4 @cpu(0)>
0表示所在维度不变化
===============
-1表示自动计算所在维度
# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.arange(0,12).reshape(4,3)print xy = x.reshape(3,-1)print yy = x.reshape(-1,3)print yy = x.reshape(-1,2)print yy = x.reshape(-1)print y
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[ 0. ?1. ?2. ?3.]
[ 4. ?5. ?6. ?7.]
[ 8. ?9. 10. 11.]]
<NDArray 3x4 @cpu(0)>
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[ 0. ?1.]
[ 2. ?3.]
[ 4. ?5.]
[ 6. ?7.]
[ 8. ?9.]
[10. 11.]]
<NDArray 6x2 @cpu(0)>
[ 0. ?1. ?2. ... ?9. 10. 11.]
<NDArray 12 @cpu(0)>
# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.arange(0,12).reshape(4,3)``print xy = x.reshape(-2)print yy = x.reshape(4,-2)print yy = x.reshape(-2,1)print yx = mx.nd.arange(0,12).reshape(2,3,2)print xy = x.reshape(2,-2)print yy = x.reshape(2,-2,1)print y
-2表示全部或余下的维度?
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[ 0. ?1. ?2.]
[ 3. ?4. ?5.]
[ 6. ?7. ?8.]
[ 9. 10. 11.]]
<NDArray 4x3 @cpu(0)>
[[[ 0.]
[ 1.]
[ 2.]]
[[ 3.]
[ 4.]
[ 5.]]
[[ 6.]
[ 7.]
[ 8.]]
[[ 9.]
[10.]
[11.]]]
<NDArray 4x3x1 @cpu(0)>
[[[ 0. ?1.]
[ 2. ?3.]
[ 4. ?5.]]
[[ 6. ?7.]
[ 8. ?9.]
[10. 11.]]]
<NDArray 2x3x2 @cpu(0)>
[[[ 0. ?1.]
[ 2. ?3.]
[ 4. ?5.]]
[[ 6. ?7.]
[ 8. ?9.]
[10. 11.]]]
<NDArray 2x3x2 @cpu(0)>
[[[[ 0.]
[ 1.]]
[[ 2.]
[ 3.]]
[[ 4.]
[ 5.]]]
[[[ 6.]
[ 7.]]
[[ 8.]
[ 9.]]
[[10.]
[11.]]]]
<NDArray 2x3x2x1 @cpu(0)>
-3表示使用2个连续维度。
# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.arange(0,12).reshape(2,3,2)print xy = x.reshape(-3,2)print yy = x.reshape(2,-3)print yy = x.reshape(0,-3)print y
[[[ 0. ?1.]
[ 2. ?3.]
[ 4. ?5.]]
[[ 6. ?7.]
[ 8. ?9.]
[10. 11.]]]
<NDArray 2x3x2 @cpu(0)>
[[ 0. ?1.]
[ 2. ?3.]
[ 4. ?5.]
[ 6. ?7.]
[ 8. ?9.]
[10. 11.]]
<NDArray 6x2 @cpu(0)>
[[ 0. ?1. ?2. ?3. ?4. ?5.]
[ 6. ?7. ?8. ?9. 10. 11.]]
<NDArray 2x6 @cpu(0)>
[[ 0. ?1. ?2. ?3. ?4. ?5.]
[ 6. ?7. ?8. ?9. 10. 11.]]
<NDArray 2x6 @cpu(0)>
mxnet-reshape
原文地址:http://blog.51cto.com/13959448/2316497