I am new to python (and even programming!), So I will try to be as clear as I can to explain my question. It may be easy for you, but I have not yet found a satisfactory result.
Here is the problem:
I have an array with negative and positive values, for example:
x = numpy.array([1, 4, 2, 3, -1, -6, -6, 5, 6, 7, 3, 1, -5, 4, 9, -5, -2, -1, -4])
I would like to summarize ONLY negative values โโthat are continuous , i.e. only the sum (-1, -6, -6), sum (-5, - 2, -1, -4), etc. I tried using numpy.where as well as numpy.split based on the condition.
For instance:
for i in range(len(x)): if x[i] < 0.: y[i] = sum(x[i])
However, as expected, I just got a summation of all the negative values โโin the array. In this case, sum (- 1, -6, -6, -5, -5, -2, -1, -4) Can the guys share with me an aesthetic and effective way to solve this problem? I would appreciate any response to this.
Thank you very much