[SciPy-user] Extract local minima
nwagner at iam.uni-stuttgart.de
Mon Jun 19 13:33:50 CDT 2006
On Mon, 19 Jun 2006 11:07:17 -0500
Robert Kern <robert.kern at gmail.com> wrote:
> Nils Wagner wrote:
>> Hi all,
>> Is there a way to extract local minima from the column
>>vector stored in
>> data.mtx ?
> The general scheme would be to look for elements x[i]
>such that (x[i-1] > x[i])
> & (x[i+1] > x[i]).
> import numpy as np
> x = ...
> xp = x[2:]
> xm = x[:-2]
> x0 = x[1:-1]
> minima = np.where((xp > x0) & (xm > x0)) + 1
> There are some additional things you will want to do to
>make it robust, like
> checking the endpoints and looking places where there
>are equal values. These
> are left as an exercise for the reader.
> Robert Kern
> "I have come to believe that the whole world is an
>enigma, a harmless enigma
> that is made terrible by our own mad attempt to
>interpret it as though it had
> an underlying truth."
> -- Umberto Eco
> SciPy-user mailing list
> SciPy-user at scipy.net
Thank you very much !
The result is promising.
from scipy import *
from pylab import plot, show, scatter
x = rand(100)
xp = x[2:]
xm = x[:-2]
x0 = x[1:-1]
minima=where((xp > x0) & (xm > x0))+1
More information about the SciPy-user