[Numpy-discussion] contiguous true
Sat Mar 1 00:56:41 CST 2008
On 01/03/2008, Charles R Harris <email@example.com> wrote:
> > On Fri, Feb 29, 2008 at 10:53 AM, John Hunter <firstname.lastname@example.org> 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
If you have a fondness for the baroque, you can try
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).
More information about the Numpy-discussion