亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在python數組中找到接近數字的值并將其索引

在python數組中找到接近數字的值并將其索引

汪汪一只貓 2022-10-11 10:12:21
這是我到目前為止的代碼:import numpy as np#make amplitude and sample arraysamplitude=[0,1,2,3, 5.5, 6,5,2,2, 4, 2,3,1,6.5,5,7,1,2,2,3,8,4,9,2,3,4,8,4,9,3]#print(amplitude)#split arrays up into a line for each sampletraceno=5                  #number of traces in filesamplesno=6                #number of samples in each trace. This wont change.amplitude_split=np.array(amplitude, dtype=np.int).reshape((traceno,samplesno))print(amplitude_split)#find max value of tracemax_amp=np.amax(amplitude_split,1)print(max_amp)#find index of max valueind_max_amp=np.argmax(amplitude_split, axis=1, out=None)#print(ind_max_amp)#find 90% of max value of traceamp_90=np.amax(amplitude_split,1)*0.9print(amp_90)我想在數組的每一行中找到最接近相應 amp_90 的值。我也希望能夠獲得這個數字的索引。請幫忙!nb 我知道這很容易用肉眼完成,但在我將其應用于我的真實數據之前,它是一個測試數據集!
查看完整描述

1 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

IIUC,您可以執行以下操作:


# find the indices of the min absolute difference 

indices = np.argmin(np.abs(amplitude_split - amp_90[:, None]), axis=1)


# get the values at those positions

result = amplitude_split[np.arange(5), indices]


print(result)


查看完整回答
反對 回復 2022-10-11
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號