标签:numpy scalar editor net code array ora oat float
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.zeros((3, 5, 2))
print x.size
x = mx.nd.array([1, 2, 3, 4])
print x.context
print type(x.context)
x = mx.nd.zeros((2,3))
print x.dtype
y = mx.nd.zeros((2,3), dtype=‘int32‘)
print y.dtype
x = mx.nd.ones((1,), dtype=‘int32‘)
print x.asscalar()
print type(x.asscalar())
x = mx.nd.zeros((2,3), dtype=‘float32‘)
y = x.astype(‘int32‘)
print y.dtype
30
cpu(0)
<class ‘mxnet.context.Context‘>
<type ‘numpy.float32‘>
<type ‘numpy.int32‘>
1
<type ‘numpy.int32‘>
<type ‘numpy.int32‘>
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import mxnet as mx
import numpy as np
x = mx.nd.ones((2,3))
y = mx.nd.zeros((2,3))
z = x.copyto(y)
print z is y
print y
True
[[1. 1. 1.]
?[1. 1. 1.]]
<NDArray 2x3 @cpu(0)>
如果context相同,返回源内容的链接
如果context不同,则copy
>>> x = mx.nd.ones((2,3))
>>> y = x.as_in_context(mx.cpu())
>>> y is x
True
>>> z = x.as_in_context(mx.gpu(0))
>>> z is x
False
标签:numpy scalar editor net code array ora oat float
原文地址:http://blog.51cto.com/13959448/2316478