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

mxnet-操作符

时间:2018-11-15 00:17:58      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:import   coding   als   cpu   .sh   cat   maximum   slice   asn   

# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import mxnet as mx import numpy as np a = mx.nd.ones((2,3)) b = mx.nd.ones((2,3)) c = a + b d = - c e = mx.nd.sin(c**2).T f = mx.nd.maximum(a, c) f.asnumpy() print e,f,d a = mx.nd.arange(4).reshape((2,2)) b = a * a c = mx.nd.dot(a,a) print("b: %s, \n c: %s" % (b.asnumpy(), c.asnumpy()))

[[-0.7568025 -0.7568025]
[-0.7568025 -0.7568025]
[-0.7568025 -0.7568025]]
<NDArray 3x2 @cpu(0)>
[[2. 2. 2.]
[2. 2. 2.]]
<NDArray 2x3 @cpu(0)>
[[-2. -2. -2.]
[-2. -2. -2.]]
<NDArray 2x3 @cpu(0)>
b: [[0. 1.]
[4. 9.]],
c: [[ 2. 3.]
[ 6. 11.]]


 # -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import mxnet as mx
import numpy as np
a1 = mx.nd.array([10,2,23])
a2 = mx.nd.array([1,12,3])

f1 = mx.nd.maximum(a1, a2)
f2 = mx.nd.minimum(a1, a2)
print f1,f2

a = mx.nd.ones((2,2))
b = mx.nd.ones(a.shape)
b += a
print b

a = mx.nd.array(np.arange(6).reshape(3,2))
print a
a[1:2] = 1
print a[:].asnumpy()

d = mx.nd.slice_axis(a, axis=1, begin=1, end=2)
print d.asnumpy()

d = mx.nd.slice_axis(a, axis=0, begin=0, end=1)
print d.asnumpy()

[10. 12. 23.]
<NDArray 3 @cpu(0)>
[1. 2. 3.]
<NDArray 3 @cpu(0)>

[[2. 2.]
[2. 2.]]
<NDArray 2x2 @cpu(0)>

[[0. 1.]
[2. 3.]
[4. 5.]]
<NDArray 3x2 @cpu(0)>
[[0. 1.]
[1. 1.]
[4. 5.]]
[[1.]
[1.]
[5.]]
[[0. 1.]]

 # -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import mxnet as mx
import numpy as np
a = mx.nd.array(np.arange(24))
b = a.reshape((2,3,4))
print b.asnumpy()

a = mx.nd.ones((2,3))
b = mx.nd.ones((2,3))*2
c = mx.nd.concat(a,b)
print c.asnumpy()

a = mx.nd.ones((2,3))
b = mx.nd.sum(a)
print b.asnumpy()

c = mx.nd.sum_axis(a, axis=1)
print c.asnumpy()

a = mx.nd.array(np.arange(6).reshape(6,1))
print a
b = a.broadcast_to((6,5))  #
print b.asnumpy()

[[[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.]
[ 8. 9. 10. 11.]]

[[12. 13. 14. 15.]
[16. 17. 18. 19.]
[20. 21. 22. 23.]]]
[[1. 1. 1. 2. 2. 2.]
[1. 1. 1. 2. 2. 2.]]
[6.]
[3. 3.]

[[0.]
[1.]
[2.]
[3.]
[4.]
[5.]]
<NDArray 6x1 @cpu(0)>
[[0. 0. 0. 0. 0.]
[1. 1. 1. 1. 1.]
[2. 2. 2. 2. 2.]
[3. 3. 3. 3. 3.]
[4. 4. 4. 4. 4.]
[5. 5. 5. 5. 5.]]

 # -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import mxnet as mx
import numpy as np

a = mx.nd.ones((2,3))
c = mx.nd.sum_axis(a, axis=0)
print c.asnumpy()

a = mx.nd.array(np.arange(6).reshape(6,1))
print a
c = a.reshape((2,1,1,3))
print c
d = c.broadcast_to((2,2,2,3))
print d.asnumpy()

a = mx.nd.ones((3,2))
b = mx.nd.ones((1,2))
c = a + b
print c.asnumpy()

a = mx.nd.ones((2,2))
b = a
print b is a
c=b.copy()
print c is a
d=c
a.copyto(d)
print d
print d is a,d is c

[2. 2. 2.]

[[0.]
[1.]
[2.]
[3.]
[4.]
[5.]]
<NDArray 6x1 @cpu(0)>

[[[[0. 1. 2.]]]

[[[3. 4. 5.]]]]
<NDArray 2x1x1x3 @cpu(0)>
[[[[0. 1. 2.]
[0. 1. 2.]]

[[0. 1. 2.]
[0. 1. 2.]]]

[[[3. 4. 5.]
[3. 4. 5.]]

[[3. 4. 5.]
[3. 4. 5.]]]]
[[2. 2.]
[2. 2.]
[2. 2.]]
True
False

[[1. 1.]
[1. 1.]]
<NDArray 2x2 @cpu(0)>
False True

mxnet-操作符

标签:import   coding   als   cpu   .sh   cat   maximum   slice   asn   

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

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