分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

mxnet-type,context,copyto

发布时间:2023-09-06 02:22责任编辑:苏小强关键词:暂无标签
# -*- 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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved