0

How i can get the position of 4,3,6 present in this order in one array?

import numpy as np

# This is where i want find the position of the series
# as you can see  the series  are
#                                  here                 here                 here    

a = np.array([5,6,7, 5,4,7, 3,6,7, 4,3,6 ,1,2,3, 4,5,6, 4,3,6, 9,3,2, 3,4,4, 4,3,6])

The result i would is:

[9 , 18 , 27 ]

my first solution is :

#the series i'm looking for 

se=[4,3,6]

#where append the results
r = []

for i in range(len(a)-2):

   if a[i+0] == se[0] and a[i+1] == se[1] and a[i+2] == se[2]:
       r.append(i)


print(r) 

output:

[9,18,27]

How i can obtain this result in a fast way with large 'a' array?

Thanks to all .

Mario Abbruscato
  • 819
  • 1
  • 7
  • 9

0 Answers0