# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.arange(0a,12).reshape(4,3)
print x
y = x.reshape(3,0)
print y
y = x.reshape(0,3)
print y
y = x.reshape(0,2)
print y
y = x.reshape(0)
print y
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[0. 1. 2.]
[3. 4. 5.]
[6. 7. 8.]]
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[0. 1.]
[2. 3.]
[4. 5.]
[6. 7.]]
[0. 1. 2. 3.]
0表示所在维度不变化
===============
-1表示自动计算所在维度
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.arange(0,12).reshape(4,3)
print x
y = x.reshape(3,-1)
print y
y = x.reshape(-1,3)
print y
y = x.reshape(-1,2)
print y
y = x.reshape(-1)
print y
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.]
[ 8. 9. 10. 11.]]
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[ 0. 1.]
[ 2. 3.]
[ 4. 5.]
[ 6. 7.]
[ 8. 9.]
[10. 11.]]
[ 0. 1. 2. … 9. 10. 11.]
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.arange(0,12).reshape(4,3)``
print x
y = x.reshape(-2)
print y
y = x.reshape(4,-2)
print y
y = x.reshape(-2,1)
print y
x = mx.nd.arange(0,12).reshape(2,3,2)
print x
y = x.reshape(2,-2)
print y
y = x.reshape(2,-2,1)
print y
-2表示全部或余下的维度
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]
[ 9. 10. 11.]]
[[[ 0.]
[ 1.]
[ 2.]]
[[ 3.]
[ 4.]
[ 5.]]
[[ 6.]
[ 7.]
[ 8.]]
[[ 9.]
[10.]
[11.]]]
[[[ 0. 1.]
[ 2. 3.]
[ 4. 5.]]
[[ 6. 7.]
[ 8. 9.]
[10. 11.]]]
[[[ 0. 1.]
[ 2. 3.]
[ 4. 5.]]
[[ 6. 7.]
[ 8. 9.]
[10. 11.]]]
[[[[ 0.]
[ 1.]]
[[ 2.]
[ 3.]]
[[ 4.]
[ 5.]]]
[[[ 6.]
[ 7.]]
[[ 8.]
[ 9.]]
[[10.]
[11.]]]]
-3表示使用2个连续维度。
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.arange(0,12).reshape(2,3,2)
print x
y = x.reshape(-3,2)
print y
y = x.reshape(2,-3)
print y
y = x.reshape(0,-3)
print y
[[[ 0. 1.]
[ 2. 3.]
[ 4. 5.]]
[[ 6. 7.]
[ 8. 9.]
[10. 11.]]]
[[ 0. 1.]
[ 2. 3.]
[ 4. 5.]
[ 6. 7.]
[ 8. 9.]
[10. 11.]]
[[ 0. 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10. 11.]]
[[ 0. 1. 2. 3. 4. 5.]
[ 6. 7. 8. 9. 10. 11.]]