let say I have the following array :
array([2, 0, 0, 1, 0, 1, 0, 0])
how do I get the indices's where I have occurrence of sequence of values. In this case [0,0]. i.e. I should get back :
[1,2,6,7]
thanks
let say I have the following array :
array([2, 0, 0, 1, 0, 1, 0, 0])
how do I get the indices's where I have occurrence of sequence of values. In this case [0,0]. i.e. I should get back :
[1,2,6,7]
thanks
Here's one way to do it iteratively with a forloop
def find_seq(a_list, val):
seqs = []
for i, item in enumerate(a_list[:-1]):
if item == val and a_list[i + 1] == val:
#or you could append a tuple: seqs.append((i, i+1))
seqs.append(i)
seqs.append(i + 1)
retu seqs
print(find_seq([2, 0, 0, 1, 0, 1, 0, 0], 0))
برچسب:
نویسنده: استخدام کار