import numpy as np
a = np.array(
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
)
np.random.shuffle(a) # 打乱顺序
a_max = np.partition(a, -1)[-1] # 最大值:14
a_2nd_max = np.partition(a, -2)[-2] # 次最大值:13
a_min = np.partition(a, 0)[0] # 最小值:5
a_2nd_min = np.partition(a, 1)[1] # 次最小值:6
see also
numpy官方文档:numpy.partition