1

I have matlab code and I want to change it to python code. To do this , I want to know how to get index of max value of histogram in python

In matlab it's easy to get index

for example

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

but how can I get in python?

I know there's matplotlib and numpy to get histogram. but I don't know how to get max value and index of it.

twi
  • 127
  • 1
  • 3
  • 8

1 Answers1

0

Look for the largest value in a list using max, and then index to find it's position:

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

val = max(l)
idx = l.index(val)
Chen A.
  • 10,140
  • 3
  • 42
  • 61