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

mxnet-读写文件

时间:2018-11-15 00:14:23      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:pre   rip   Edito   dfs   读取   pen   bin   序列化   [1]   

# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import mxnet as mx import numpy as np import pickle as pkl #1.pickle a = mx.nd.ones((2, 3)) # 序列化存储 data = pkl.dumps(a) pkl.dump(data, open(‘tmp.pickle‘, ‘wb‘)) # 序列化读取 data = pkl.load(open(‘tmp.pickle‘, ‘rb‘)) b = pkl.loads(data) print b.asnumpy() #2.直接读写 a = mx.nd.ones((2,3)) b = mx.nd.ones((5,6)) mx.nd.save("temp.ndarray", [a,b]) c = mx.nd.load("temp.ndarray") print c d = {‘a‘:a, ‘b‘:b} mx.nd.save("temp.ndarray", d) c = mx.nd.load("temp.ndarray") print c

[[1. 1. 1.]
?[1. 1. 1.]]
[
[[1. 1. 1.]
?[1. 1. 1.]]
<NDArray 2x3 @cpu(0)>,?
[[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]]
<NDArray 5x6 @cpu(0)>]
{‘a‘:?
[[1. 1. 1.]
?[1. 1. 1.]]
<NDArray 2x3 @cpu(0)>, ‘b‘:?
[[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]
?[1. 1. 1. 1. 1. 1.]]
<NDArray 5x6 @cpu(0)>}

a = mx.nd.ones((2, 3))
mx.nd.save("temp.ndarray", [a,])
a <- mx.nd.load("temp.ndarray")
as.array(a[[1]])
##      [,1] [,2] [,3]
## [1,]    1    1    1
## [2,]    1    1    1
mx.nd.save(‘s3://mybucket/mydata.ndarray‘, [a,])  # if compiled with USE_S3=1
mx.nd.save(‘hdfs///users/myname/mydata.bin‘, [a,])  # if compiled with USE_HDFS=1

mxnet-读写文件

标签:pre   rip   Edito   dfs   读取   pen   bin   序列化   [1]   

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

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