On 01/03/2008, Charles R Harris <[EMAIL PROTECTED]> wrote:

> > On Fri, Feb 29, 2008 at 10:53 AM, John Hunter <[EMAIL PROTECTED]> wrote:
> > > I have a boolean array and would like to find the lowest index "ind"
> > > where N contiguous elements are all True.  Eg, if x is

[...]

> Oops, ind = arange(len(x)). I suppose nonzero would work as well.

I'm guessing you're alluding to the fact that diff(nonzero(x)) gives
you a list of the run lengths of Falses in x (except possibly for the
first one).

If you have a fondness for the baroque, you can try

numpy.where(numpy.convolve(x,[1,]*N,'valid')==N)

For large N this can even use Fourier-domain convolution (though you'd
then have to be careful about round-off error).

Silly, really, it's O(NM) or O(N log M) instead of O(N).

Anne
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to