攝影或3C

Python numpy.argmin(array) 傳回沿軸最小值的index,參數不能用list,可用numpy.array(),把list轉為array

Freqs=[10000,11000,12000,13000,14000,15000]  #list

import numpy as np
FreqsSelList=np.array( Freqs )  #array

for i in range(len(FreqsSelList)):
idx = np.argmin(abs(Freqs-FreqsSelList[i])) ;
print(“abs”,abs(Freqs-FreqsSelList[i]))
print(“idx”,idx)

 

需要注意abs()

該物件為array,非list

若依註解處寫法:

FreqsSelList=[10000,11000,12000,13000,14000,15000]

會出現 TypeError:

unsupported operand type(s) for -: ‘list’ and ‘int’

 

儲蓄保險王

儲蓄險是板主最喜愛的儲蓄工具,最喜愛的投資理財工具則是ETF,最喜愛的省錢工具則是信用卡