scipy.signal.
argrelextrema#
- scipy.signal.argrelextrema(data, comparator, axis=0, order=1, mode='clip')[source]#
計算 data 的相對極值。
- 參數:
- datandarray
在其中尋找相對極值的陣列。
- comparatorcallable
用於比較兩個資料點的函式。應接受兩個陣列作為引數。
- axisint, optional
從 data 中選擇的軸。預設值為 0。
- orderint, optional
在比較中,每側要使用多少個點來判斷
comparator(n, n+x)
是否為 True。- modestr, optional
如何處理向量的邊緣。 ‘wrap’(環繞)或 ‘clip’(將溢位視為與最後一個(或第一個)元素相同)。預設值為 ‘clip’。請參閱
numpy.take
。
- 回傳:
- extrematuple of ndarrays
整數陣列中極大值的索引。
extrema[k]
是 data 的軸 k 的索引陣列。 請注意,即使 data 是一維的,回傳值也是一個元組。
註解
在版本 0.11.0 中新增。
範例
>>> import numpy as np >>> from scipy.signal import argrelextrema >>> x = np.array([2, 1, 2, 3, 2, 0, 1, 0]) >>> argrelextrema(x, np.greater) (array([3, 6]),) >>> y = np.array([[1, 2, 1, 2], ... [2, 2, 0, 0], ... [5, 3, 4, 4]]) ... >>> argrelextrema(y, np.less, axis=1) (array([0, 2]), array([2, 1]))