新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
python中怎么尋找離散序列極值點(diǎn)-創(chuàng)新互聯(lián)
python中怎么尋找離散序列極值點(diǎn),很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
使用 scipy.signal 的 argrelextrema 函數(shù)(API),簡(jiǎn)單方便
import numpy as np import pylab as pl import matplotlib.pyplot as plt import scipy.signal as signal x=np.array([ 0, 6, 25, 20, 15, 8, 15, 6, 0, 6, 0, -5, -15, -3, 4, 10, 8, 13, 8, 10, 3, 1, 20, 7, 3, 0 ]) plt.figure(figsize=(16,4)) plt.plot(np.arange(len(x)),x) print x[signal.argrelextrema(x, np.greater)] print signal.argrelextrema(x, np.greater) plt.plot(signal.argrelextrema(x,np.greater)[0],x[signal.argrelextrema(x, np.greater)],'o') plt.plot(signal.argrelextrema(-x,np.greater)[0],x[signal.argrelextrema(-x, np.greater)],'+') # plt.plot(peakutils.index(-x),x[peakutils.index(-x)],'*') plt.show()
[25 15 6 10 13 10 20] (array([ 2, 6, 9, 15, 17, 19, 22]),)
但是存在一個(gè)問(wèn)題,在極值有左右相同點(diǎn)的時(shí)候無(wú)法識(shí)別,但是個(gè)人認(rèn)為在實(shí)際的使用過(guò)程中極少會(huì)出現(xiàn)這種情況,所以可以忽略。
x=np.array([ 0, 15, 15, 15, 15, 8, 15, 6, 0, 6, 0, -5, -15, -3, 4, 10, 8, 13, 8, 10, 3, 1, 20, 7, 3, 0 ]) plt.figure(figsize=(16,4)) plt.plot(np.arange(len(x)),x) print x[signal.argrelextrema(x, np.greater)] print signal.argrelextrema(x, np.greater) plt.plot(signal.argrelextrema(x,np.greater)[0],x[signal.argrelextrema(x, np.greater)],'o') plt.plot(signal.argrelextrema(x,np.less)[0],x[signal.argrelextrema(x, np.less)],'+') plt.show()
[15 6 10 13 10 20] (array([ 6, 9, 15, 17, 19, 22]),)
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。
標(biāo)題名稱:python中怎么尋找離散序列極值點(diǎn)-創(chuàng)新互聯(lián)
瀏覽地址:http://fisionsoft.com.cn/article/dhosep.html