I have a dataset like
x y
1 0.34
2 0.3432
3 0.32
4 0.35
5 0.323
6 0.3623
7 0.345
8 0.32
9 0.31
10 0.378
11 0.34
12 0.33
13 0.31
14 0.33
15 0.34
For this dataset I want to perform a task which will go through my dataset and will count the number of occurrences above a cutoff if the length of occurrence is above M.
The cutoff and M will be system arguments.
So if the cutoff is 0.32 and M is 1 it will print out a list like
[2, 4, 3, 2]
Logic: First two values in second column are above 0.32 and the length of the is greater than M=1 hence it printed out 2 and 4,3,2 so on.
I need a help to write the argument so that if x >cutoff and length of broken is >M it will print out the length of broken frames (so the same out put as above). Any help?
The structure should look like following (I am not sure how to place the argument in place of XXX)
def get_input(filename):
with open(filename) as f:
next(f) # skip the first line
input_list = []
for line in f:
input_list.append(float(line.split()[1]))
return input_list
def countwanted(input_list, wantbroken, cutoff,M):
def whichwanted(x):
if(wantbroken): return x > cutoff
else: return x < cutoff
XXX I think here I need to add the criteria for M but not sure how?
filename=sys.argv[1]
wantbroken=(sys.argv[2]=='b' or sys.argv[2]=='B')
cutoff=float(sys.argv[3])
M=int(sys.argv[4])
input_list = get_input(filename)
broken,lifebroken=countwanted(input_list,True,cutoff,M)
#closed,lifeclosed=countwanted(input_list,False,cutoff,M)
print(lifebroken)
#print(lifeclosed)
Or maybe there is a simpler way to write it.