Hi, I was hoping someone could help out a python novice like me.
I want to find in my data when there is three or more 1s in a row. This is a sample of what my input data would look like below. With the first number in each column being a position and the rest of the numbers being either not significant (0) or significant (1).
78 79 80 81 82 83
0 0 0 0 0 0
1 0 0 1 1 0
0 0 1 1 1 0
0 1 1 1 1 1
This is my code so far:
def sigfind(in_file,num_repeats):
numbers = []
for line in in_file:
numbers = line.split()
i = 0
out_file=[]
while i < len(numbers)-1:
if [numbers[i]] == [numbers[i+1]] == num_repeats:
out_file.append(number[i])
i += num_repeats
else:
i += 1
sigfind(in_file,3)
But I am having trouble finding the consecutive numbers as well as outputting it in the right format.
The way in which I want to output it is something like below, where it will tell me the row number (with the row numbering not including the first number --> the position), when the consecutive 1s started and where they ended; if there was three or more 1s in a row.
eg.
row start_pos end_pos
3 80 82
4 79 83
I hope this makes sense....Anyone have any ideas?
Thanks!