Use numpy to get the maximum value of the list

import numpy as np

b=[[1,8,7],[4,5,6]]
id = np.argmax(b,axis=1)
m = np.amax(b,axis=1)
print('每行最大值:{},索引:{}'.format(m,id))
# 每行最大值:[8 6],索引:[1 2]
id = np.argmax(b,axis=0)
m = np.amax(b,axis=0)
print('每列最大值:{},索引:{}'.format(m,id))
# 每列最大值:[4 8 7],索引:[1 0 0]
id = np.argmax(b)
m = np.amax(b)
print('最大值:{},索引:{}'.format(m,id))
# 最大值:8,索引:1

Guess you like

Origin blog.csdn.net/a272881819/article/details/121979838