Hi Kurdt,

On Mon, 17 Sep 2007 12:18:51 +0200, "Kurdt Bane" <[EMAIL PROTECTED]>
wrote:
> I've got an 1-D array of bools and I'd like to find the length of the
> first
> contiguous sequence of True values, starting from position [0] of the
> array.

One way would be:

x = N.array([True,True,False,True])
x.argmin()

> And what if I want to
> get
> a list of all the contiguous sequences of True values, above a given
> threshold?

x = N.array([True,True,False,False,False,True,False,False])

jumps, = N.where(N.diff(x))
idx = N.concatenate(([0],jumps+1,[-1]))
print [x[a:b] for (a,b) in zip(idx[:-1],idx[1:]) if x[a]]

Cheers
Stéfan


_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to