任務描述:
現在有一個二維數組test_y,我想要獲取每一行的最大值,以及最大值所在索引值
代碼:
隨機生成一個3行4列的數組,利用np.argmax()函數獲取最大值所在索引,amax()獲取最大值的值。
import numpy as np
test_y = np.random.rand(3,4)
idx = np.argmax(test_y, axis=1)
pro = np.amax(test_y, axis=1)
print(idx)
print(pro)
運行結果