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’



![Python: pandas.DataFrame 如何對某些欄做格式化字串? apply(); applymap() ; map() 的差別? df[‘Salary’] = df[‘Salary’].map( ‘${:,.2f}’ .format) Python: pandas.DataFrame 如何對某些欄做格式化字串? apply(); applymap() ; map() 的差別? df[‘Salary’] = df[‘Salary’].map( ‘${:,.2f}’ .format)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/05/20230527091636_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)





![Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter Python: 如何使用functools.reduce逐步縮減可迭代對象,合併為單個結果? import functools; product = functools.reduce( lambda x, y: x * y, numbers) ; reduce(function, sequence [, initial]) -> value ; map(function, iterable) ; filter(function, iterable) ; map ; filter](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/06/20230626093403_49.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言