I would like to identify state transitions in a data set. An example is: "At which index does the sin(x) fall below 0.5?"
The only way I could think of is like this:
a = np.arange(0,10,.01)
b= np.sin(a)
c = np.roll(b,1)
c[:1] = 0
print(a[(.5 > b) & (.5< c)])
[2.62 8.91]
Can I do that without an additional array c? How can I detect cases like "At which index does sin(x) fall below 0.5 and stay there for 7 samples?" Would i need 7 additional arrays?