-
Notifications
You must be signed in to change notification settings - Fork 0
/
something.py
52 lines (41 loc) · 1.34 KB
/
something.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
51
52
import sys
import os
import numpy as np
def loadDataFromFile(filename, delimiter='\t'):
return np.genfromtxt(filename, delimiter='\t')
def collatePoints(array):
data = {} #empty dictionary
for row in array:
x, y = row #unpack the row into x and y values
if x in data:
# We've already seen data at this X, so append the y value to our list of seen y values at this X
data[x].append(y)
else:
# We haven't seen data at this X yet, so add the y value in a new list (so we can add more later, if needed)
data[x] = [y]
return data
def averagePoints(point_dict):
averages = []
for x, values in point_dict.items():
y = np.average(values)
averages.append([x,y])
return np.array(averages)
def main():
inputfilename = sys.argv[1]
outputfilename = inputfilename + ".out.txt"
arr = loadDataFromFile(inputfilename)
#trim the third column
arr = arr[:,0:2]
collated = collatePoints(arr)
averages = averagePoints(collated)
try:
os.remove(outputfilename)
except FileNotFoundError:
pass
with open(outputfilename, 'w') as output:
output.write(inputfilename + "\n")
for x, y in averages:
output.write("{},{}\n".format(x,y))
return 0
if __name__ == '__main__':
sys.exit(main())