[Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Neal Becker
In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater = numpy.arange(arr.shape)[arr = T][-1] first_lower = last_greater + 1 There's probably a better way to do it, without the arange, though...

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Neal Becker
such that mag -50. How to do this efficiently? ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater = numpy.arange(arr.shape)[arr = T][-1] first_lower = last_greater + 1 There's probably a better way to do it, without the arange, though... I'm

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Neal Becker
Zachary Pincus wrote: In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater = numpy.arange(arr.shape)[arr = T][-1] first_lower = last_greater + 1 There's probably a better way to do it, without the

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
On Feb 9, 2011, at 10:58 AM, Neal Becker wrote: Zachary Pincus wrote: In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater = numpy.arange(arr.shape)[arr = T][-1] first_lower = last_greater + 1

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Alan G Isaac
On 2/9/2011 10:58 AM, Neal Becker wrote: But where is numpy's 'find_first' function? np.argmax(arrayT) (Of course that constructs a boolean array...) Alan Isaac ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread josef . pktd
On Wed, Feb 9, 2011 at 11:04 AM, Zachary Pincus zachary.pin...@yale.edu wrote: On Feb 9, 2011, at 10:58 AM, Neal Becker wrote: Zachary Pincus wrote: In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
As before, the line below does what you said you need, though not maximally efficiently. (Try it in an interpreter...) There may be another way in numpy that doesn't rely on constructing the index array, but this is the first thing that came to mind. last_greater =

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
This assumes monotonicity. Is that allowed? The twice-stated problem was: [Note to avert email-miscommunications] BTW, I wasn't trying to snipe at you with that comment, Josef... I just meant to say that this solution solves the problem as Neal posed it, though that might not be the exact

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Bruce Southey
On 02/09/2011 10:17 AM, Zachary Pincus wrote: As before, the line below does what you said you need, though not maximally efficiently. (Try it in an interpreter...) There may be another way in numpy that doesn't rely on constructing the index array, but this is the first thing that came to

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Neal Becker
Zachary Pincus wrote: On Feb 9, 2011, at 10:58 AM, Neal Becker wrote: Zachary Pincus wrote: In a 1-d array, find the first point where all subsequent points have values less than a threshold, T. Maybe something like: last_greater = numpy.arange(arr.shape)[arr = T][-1] first_lower =

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Alan G Isaac
On 2/9/2011 11:39 AM, Bruce Southey wrote: np.argmax(x5) # doesn't appear to be correct It was an answer to the particular question of how to do find_first, which it does (at the cost of a boolean array): it finds the first element greater than 5. x array([5, 4, 3, 6, 7, 3, 2, 1])

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Robert Kern
On Wed, Feb 9, 2011 at 10:48, Neal Becker ndbeck...@gmail.com wrote: Still, I wonder if numpy would benefit from a 'find_first' function. I certainly could have used one many times. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread josef . pktd
On Wed, Feb 9, 2011 at 11:25 AM, Zachary Pincus zachary.pin...@yale.edu wrote: This assumes monotonicity. Is that allowed? The twice-stated problem was: [Note to avert email-miscommunications] BTW, I wasn't trying to snipe at you with that comment, Josef... I just meant to say that this

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Zachary Pincus
In a 1-d array, find the first point where all subsequent points have values less than a threshold. This doesn't imply monotonicity. Suppose with have a sin curve, and I want to find the last trough. Or a business cycle and I want to find the last recession. Unless my english

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread josef . pktd
On Wed, Feb 9, 2011 at 1:18 PM, Zachary Pincus zachary.pin...@yale.edu wrote: In a 1-d array, find the first point where all subsequent points have values less than a threshold. This doesn't imply monotonicity. Suppose with have a sin curve, and I want to find the last trough. Or a

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Mark Bakker
I recently needed a find_first function and searched the list. It has been discussed a few times before. And I haven't seen an elegant solution yet. Maybe we should file a feature request, as it would be awfully nice to have? Mark Still, I wonder if numpy would benefit from a 'find_first'

Re: [Numpy-discussion] how to do this efficiently?

2011-02-09 Thread Neal Becker
Mark Bakker wrote: I recently needed a find_first function and searched the list. It has been discussed a few times before. And I haven't seen an elegant solution yet. Maybe we should file a feature request, as it would be awfully nice to have? Mark Still, I wonder if numpy would