nowhy

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一.数据打包pickle

 

 

 

 

 二.dict,tuple.ndarray的数据处理,

可以将numpy矩阵逐步转化为tensor的shape

import numpy as np
# import math
# make an example object to pickle
some_obj = {'x':((4.0,5.0,6.0),(1.0,2.0,3.0)), 'y':((1.0,2.0,3.0),(4.0,5.0,6.0))}//在做/时,直接返回的float   some_obj是dict,value是tuple
print(some_obj['x'])
values = some_obj.values()
names = list(set(map(lambda x: x[0], some_obj.keys())))
x = []
for name in names:
    x.append(some_obj[name])
x = np.vstack(x)##<class 'numpy.ndarray'>  shape(4, 3)
y = x.copy()//数组赋值是浅拷贝,ndarry.copy()深拷贝
for i in range(0, 4, 1):
    if i%2==0:
        y[i,:] = x[i,:]+x[i+1,:]//y[i,:]表示一行
    else:
         y[i,:] = x[i,:]-x[i-1,:]
tensor = np.reshape(y,(2,2,3))
print(np.shape(y)) #want transform x to tensor shape[2,2,3]
print(type(y))
print(tensor)
print(np.shape(tensor))

 

posted on 2019-08-31 14:25  g6z3z  阅读(211)  评论(0编辑  收藏  举报