[Numpy-discussion] looking for the Numpy to do it

Sasha ndarray at mac.com
Tue Jul 11 16:03:49 CDT 2006


Here is the solution of a half of the problem:

>>> a=array([1,2,3,0,40,50,60,0,7,8,9])
>>> 5+where(logical_and.accumulate(a[5:]!=0))
array([5, 6])

the rest is left as an exercise to the reader :-)

Hint a[::-1] will reverse a.


On 7/11/06, Mathew Yeates <myeates at jpl.nasa.gov> wrote:
> I can handle the following problem by iterating through some indices but
> I'm looking for a more elegant solution.
>
> If I have a 1d array, I want to find a contiguous nonzero region about a
> given index. For example, if a=[1,2,3,0,40,50,60,0,7,8,9] and we start
> with the index of 5, then I want the indices 4,5,6
>
> Any gurus out there?
>
> Mathew
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the Numpy-discussion mailing list