[Numpy-discussion] Find groups of true values or sequence of values

bevan bevan07@gmail....
Wed Jun 18 18:41:01 CDT 2008


Hello,

I am looking for some pointers that will hopefully get me a round an issue I 
have hit.

I have a timeseries of river flow and would like to carry out some analysis on 
the recession periods.  That is anytime the values are decreasing.  I would 
like to restrict (mask) my data to any values that are in a continuous sequence 
of 3 or more (in the example below), that are decreasing in value.

Hopefully this example helps:

import numpy as np

Flow = np.array([15.4,20.5,19.4,18.7,18.6,35.5,34.8,25.1,26.7])
FlowDiff = np.diff(Flow)
boolFlowdiff = FlowDiff>0
MaskFlow = np.ma.masked_array(Flow[1:],boolFlowdiff)

print MaskFlow
[-- 19.4 18.7 18.6 -- 34.8 25.1 --]

The output I would like is
[-- 19.4 18.7 18.6 -- -- -- --]
Where the second groups is blanked because the sequence only has 2 members.


thanks for your time,

bevan



More information about the Numpy-discussion mailing list