If I have array A
A = np.array([17, 18, 17.8, 18, 17.7, 17.4, 17, 19, 22])
I want to create the array
[17, 18, 17.8, 18, 17.7, -9999, 17, 19, 22]
The rule: if elements in A are in increasing order they are appended, but, if elements decrease two options are present:
If the elements come from a previous increase, they are appended except when the accumulated decrease is less than
-0.5; that's why17.8is appended, as well as17.7, but17.4is not appended due to the fact that the decrease from18to17.7is-0.3, added to-0.3(from17.7to17.4) is less than-0.5(-9999is appended then);If we are in a decreasing sequence and we don't come from a previous increase,
-9999is appended.
I think the key is to create an array of consecutive differences and add them in groups of 2 until the sum is below -0.5. But this is very sketchy and I am confused.
Another example: for array
B = np.array([16.0, 15.6, 15.2, 14.8, 14.4, 14.0, 18])
the solution would be
[-9999, -9999, -9999, -9999, -9999, 14.0, 18]