Python 如何获取直方图最大值的索引?

Python 如何获取直方图最大值的索引?,python,matplotlib,indexing,max,histogram,Python,Matplotlib,Indexing,Max,Histogram,我有matlab代码,我想把它改成python代码。 为此,我想知道如何在python中获得直方图最大值的索引 在matlab中很容易得到索引 比如说 array1 = [0 1 2 2 3 4 4 4 4 5 6 6 7 8 9] a1 = hist(array1,max(array1)-min(array1)) [value , index] = max(a1) u=[index-2:1:index+2] array_matrix = a1(u) % then value = 4 , in

我有matlab代码,我想把它改成python代码。 为此,我想知道如何在python中获得直方图最大值的索引

在matlab中很容易得到索引

比如说

array1 = [0 1 2 2 3 4 4 4 4 5 6 6 7 8 9]
a1 = hist(array1,max(array1)-min(array1))
[value , index] = max(a1)
u=[index-2:1:index+2]
array_matrix = a1(u)

% then value = 4 , index = 5
但是我怎样才能使用python呢

我知道有matplotlib和numpy可以得到直方图。
但是我不知道如何获取它的最大值和索引。

使用
max
在列表中查找最大值,然后
index
找到它的位置:

l = list([1, 2, 3, 4, 5])

val = max(l)
idx = l.index(val)

使用
max
查找列表中的最大值,然后使用
index
查找其位置:

l = list([1, 2, 3, 4, 5])

val = max(l)
idx = l.index(val)