# -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.zeros((3, 5, 2))print x.sizex = mx.nd.array([1, 2, 3, 4])print x.contextprint type(x.context)x = mx.nd.zeros((2,3))print x.dtypey = mx.nd.zeros((2,3), dtype=‘int32‘)print y.dtypex = 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 EditorThis is a temporary script file."""import mxnet as mximport numpy as npx = mx.nd.ones((2,3))y = mx.nd.zeros((2,3))z = x.copyto(y)print z is yprint 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 xTrue>>> z = x.as_in_context(mx.gpu(0))>>> z is xFalse
mxnet-type,context,copyto
原文地址:http://blog.51cto.com/13959448/2316478