import numpy as np
threshold = 2
signal = np.array([1, 2, 3, 4, 4, 3, 2, 1, 0, 3, 2, 1, 0, 0, 1, 1, 4, 8, 7,
    6, 5, 0])
indices_bigger_than_threshold = np.where(signal > threshold)[0]
print(indices_bigger_than_threshold)
non_consecutive = np.where(np.diff(indices_bigger_than_threshold) != 1)[0] + 1
print(non_consecutive)
first_bigger_than_threshold1 = np.zeros_like(signal, dtype=np.bool)
first_bigger_than_threshold1[indices_bigger_than_threshold[0]] = True
first_bigger_than_threshold1[indices_bigger_than_threshold[non_consecutive]
    ] = True
Эффективный поиск первых образцов, превышающих пороговое значение, в Python (и сравнение MATLAB)