我想評價
x=np.array([1,2,3])
imax=np.where(x==max(x))
顯然,imax=2但這不是np.where回報。為了獲得imax=2,我必須使用一個兩步程序,該程序涉及對 np.where 物件進行雙重取消參考:
np_where_object=np.where(x==max(x))
imax = np_where_object[0][0]
但這是不雅的。是否有避免雙重取消參考并imax=2一次性獲得的最佳實踐?我不是說np.where(x==max(x))[0][0],這仍然不雅。
uj5u.com熱心網友回復:
就在這里。它是argmax:
>>> x = np.array([1,2,3])
>>> imax = x.argmax()
>>> imax
2
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/400549.html
