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

mxnet-type,context,copyto

时间:2018-11-13 20:46:22      阅读:239      评论:0      收藏:0      [点我收藏+]

标签: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

mxnet-type,context,copyto

标签:numpy   scalar   editor   net   code   array   ora   oat   float   

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

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