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’
近期留言