[Numpy-discussion] how to do this efficiently?
zachary.pincus at yale.edu
Wed Feb 9 10:38:49 EST 2011
>>> 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 trying to find the first point in a power spectrum such that all
> points are below some level. I've started with:
> db is my power spectrum in dB, It is already reversed.
> mag = np.maximum.accumulate (db) - db[-1]
> Now all I need is to find the first point such that mag < -50. How
> to do this
Right -- that's what I showed above. Find the last point in mag that
is >= -50, and by definition the next point is the first point such
that the remainder of mag is < -50.
More information about the NumPy-Discussion