【问题标题】:how can I get index of max value of histogram? [duplicate]如何获得直方图最大值的索引? [复制]
【发布时间】:2018-04-25 04:35:42
【问题描述】:

我有 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 可以获取直方图。 但我不知道如何获得它的最大值和索引。

【问题讨论】:

    标签: python matplotlib indexing max histogram


    【解决方案1】:

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

    l = list([1, 2, 3, 4, 5])
    
    val = max(l)
    idx = l.index(val)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2018-11-10
      • 2015-01-23
      • 1970-01-01
      • 2022-10-05
      相关资源
      最近更新 更多