[Numpy-discussion] Accumulate values that are below threshold

Bevan Jenkins bevan07@gmail....
Wed Jan 7 21:02:50 CST 2009


Hello,

Sometimes the hardest part of a problem is articulating it.  Hopefully I can
describe what I am trying to do - at least enough to get some help.

I am trying to compare values to a threshold and when the values are lower than
the threshold they are added to the value in my set until the threshold is
reached.  Everytime the threshold is reached I want the index and value
(accumulated).

Hopefully the example below will help

threshold =1.0
for indx,val in enumerate(Q):
    print indx,val

0 100.0
1 20.0
2 16.0
3 7.0
4 3.0
5 1.5
6 0.8
7 0.6
8 0.5
9 0.2
10 0.2
11 0.1
12 0.1

The output I would like is (number of elements and value)
0 100.0
1 20.0
2 16.0
3 7.0
4 3.0
5 1.5
7 1.4
11 1.0


The 1st 6 elements are easy as they are all greater than or equal to the
threshold(1.0).  Once the values drop below the threshold the next value is
added until the threshold is reached.


Any help is appreciated,
Bevan Jenkins



More information about the Numpy-discussion mailing list