-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
50 lines (39 loc) · 1.03 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
""" Reading the data
Data can be treated as python dictionary objects.
A simple script to read any of the above the data is as follows:
"""
import gzip
import pandas as pd
import numpy as np
import random
from math import exp
from math import log
import matplotlib.pyplot as plt
import pickle
# 数据处理器
def Parse(path):
g = gzip.open(path, 'r')
for l in g:
yield eval(l)
# 绘制图片
def ShowPic(xSet, ySet, label='', title='', xLabel='', yLabel=''):
# 输出结果
lenElem = len(xSet)
for i in range(lenElem):
print(xSet[i], ySet[i])
# 绘制图形
plt.plot(xSet, ySet, label=label)
plt.title(title)
plt.xlabel(xLabel)
plt.ylabel(yLabel)
plt.legend(loc=4)
plt.grid(True, linewidth=0.3)
plt.show()
# 存储实例
def StoreObj(obj, storeLink):
pickle.dump(obj, open(storeLink, 'wb'))
# 读取实例,
def LoadObj(dataLink):
return pickle.load(open(dataLink, 'rb'))
def LoadData(datalink, sep=','):
return pd.read_csv(open(datalink, 'r'), sep=sep)