我正在嘗試在收集信號的全局峰值和谷值的地方實(shí)現(xiàn)峰值檢測,但是,當(dāng)我將其實(shí)現(xiàn)為一個簡單的信號時(shí),該功能可以完美運(yùn)行,沒有錯誤。但是,當(dāng)我將代碼運(yùn)行到大量數(shù)據(jù)集(大約 9000 個樣本)中時(shí),它一直給我這個錯誤:TypeError: only integer scalar arrays can be converted to a scalar index我的峰值檢測功能可以在下面找到:def custom_peakdetection_envelope(y_axis, peak_height, x_axis=None): """ keyword arguments: y_axis -- A list containing the signal over which to find peaks x_axis -- (optional) A x-axis whose values correspond to the 'y_axis' list and is used in the return to specify the position of the peaks. If omitted the index of the y_axis is used. (default: None) peak_height -- This specifies a minimum height of the peak return -- two lists [maxtab, mintab] containing the positive and negative peaks respectively. Each cell of the lists contains a tuple of: (position, peak_value) to get the average peak value do 'np.mean(maxtab, 0)[1]' on the results """ global amplitude_envelope_y global amplitude_envelope_x maxtab = [] mintab = [] maxthresh = [] minthresh = [] ax = [] amplitude_envelope_mx = [] amplitude_envelope_mn = [] if x_axis is None: x = arange(len(y_axis)) else: x = asarray(x_axis) y = asarray(y_axis) ax.append((x,y)) if len(y) != len(x): sys.exit('Input vectors y and x must have same length') if not isscalar(peak_height): sys.exit('Input argument peak_height must be a scalar') # if peak_height <= 0: # sys.exit('Input argument peak_height must be positive') # maxima and minima candidates are temporarily stored in mx and mn respectively: mn, mx = np.Inf, -np.Inf mnpos, mxpos = NaN, NaN
1 回答

冉冉說
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個贊
也許process_x_max_peak
必須更改為容納整數(shù)。嘗試以下操作:
process_y[process_x_max_peak.astype(int)]
添加回答
舉報(bào)
0/150
提交
取消