码迷,mamicode.com
首页 > Web开发 > 详细

mxnet-reshape

时间:2018-11-13 20:14:29      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:维度   temporary   editor   script   imp   array   连续   net   变化   

# -*- 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.]]
<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 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.]]
<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 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.]]
<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 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.]]]
<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

标签:维度   temporary   editor   script   imp   array   连续   net   变化   

原文地址:http://blog.51cto.com/13959448/2316497

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!