-
Notifications
You must be signed in to change notification settings - Fork 0
/
csvproc.py
27 lines (24 loc) · 892 Bytes
/
csvproc.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
import os
import numpy as np
import scipy.stat as st
def normdata(dirs):
for name in dirs:
outname = name + '-znorm'
if not os.path.exists(outname):
os.makedirs(outname)
for fname in os.listdir(name):
values = [[],[],[],[],[]]
zvalues = []
f = open(fname, 'r')
for line in f:
items = line.split(',')
for item,dlist in zip(items, values): dlist.append(item)
zvalues.extend(np.array(values.pop(0)))
for vlist in values:
arr = np.array(vlist)
zvalues.extend(st.zscore(arr))
f.close()
fout = open(outname + '/' + fname, 'w')
for val in zip(*zvalues):
fout.write('{},{},{},{},{}\n'.format(*val))
normdata(['inputs','separated-templates'])