Используйте np.cumsum()
и возьмите различия между индексами элементов 5.
import numpy as np
np.random.seed(456) # Make results repeatable
arr= np.random.randint(2, size=100)
arr
# array([1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1,
# 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1,
# 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1,
# 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0,
# 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1])
cumulate = np.zeros(arr.shape[0]+1, dtype = np.int)
cumulate[1:] = arr.cumsum() # First item in the array must be zero
diff = cumulate[5:]-cumulate[:-5]
cumulate
# array([ 0, 1, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 9, 9, 10,
# 11, 12, 12, 13, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17,
# 17, 17, 18, 18, 18, 18, 18, 19, 19, 20, 20, 20, 21, 22, 23, 24, 25,
# 25, 25, 26, 26, 27, 27, 28, 28, 28, 29, 30, 30, 30, 30, 31, 32, 33,
# 34, 35, 36, 36, 36, 37, 38, 38, 38, 39, 39, 40, 41, 42, 42, 42, 42,
# 43, 44, 44, 45, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 52])
np.where( diff == 5 )
# (array([46, 65, 66]),)
np.where возвращает кортеж массивов, поэтому [0] [0] для получения требуемого индекса.
np.where(diff == 5)[0][0]
# 46