python找列表中最大值所在的位置

来源:互联网 发布:网络药房 编辑:程序博客网 时间:2024/06/03 14:36


>>> b=[[3, 4, 5], [3, 4, -9], [5, 5, 3]]

>>> np.amax(b)              #找最大元素,可以防止使用max有多个最大值的情况
5
>>> c=np.where(b==np.max(b))
>>> c
(array([0, 2, 2], dtype=int32), array([2, 0, 1], dtype=int32))   最大值所在的行列