2022-05-08|閱讀時間 ‧ 約 2 分鐘

Python — (tf/np).argmax()

tensorflow和numpy 中都有個argmax()
兩種用法都一樣(差別在tensorflow 要用sess.run()啟動)下面只展示numpy
用法如下
import numpy as np
arr = np.array([[1, 10, 3], [6, 5, 11], [7, 8, 9], [12, 2, 4]])
print('axis=0', np.argmax(arr, axis=0))
print('axis=1', np.argmax(arr, axis=1))# arr[0] = [1, 10,  3]
# arr[1] = [6,  5, 11]
# arr[2] = [7,  8,  9]
# arr[3] = [12, 2,  4]
結果
axis=0 [3 0 1]
axis=1 [1 2 2 0]
**當axis=0時,會比對在column中最大數字回傳它的索引值
**當axis=1時,會比對在row中最大數字回傳它的索引值
分享至
成為作者繼續創作的動力吧!
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

發表回應

成為會員 後即可發表留言