I want to create a function that takes as input a list (or numpy array) A and a number L. A is full of 0 and 1 and the goal is to keep the sub-sequences of 1 if they surpass L in length. I wrote a function to do it fix(A,L) but it takes to long to run so I wanted to know if their is a faster way of doing this.
def fix(A,L):
i=0
while True:
if i==len(A):
return(A)
if A[i]==1:
s=0
for j in range(i,len(A)):
if A[j]==1:
s+=1
continue
else:
if s>=L:
break
else:
A[i:j]=[0]*len(A[i:j])
break
if A[j]==1 and s<L:
A[i:j+1]=[0]*len(A[i:j+1])
i=j+1
else:
i+=1
continue
if I call fix([1,0,0,1,1,1,0,1,1,1,1,0,1,1,0,1], 3) it returns [0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,0] which is the correct answer.

