I have a function that ends up putting the results on the list. I then use max(my_list) to give me the maximum of that list. It gives 12. But now I want to now how far into this list the maximum lies. So I can find the corresponding element of another list my_angles
Asked
Active
Viewed 27 times
1 Answers
0
You can either use the built-in functions or numpy.
Built-in functions
my_list = [0, 5, 4, 9, -2, 6]
max_value = max(my_list)
idx = my_list.index(max_value)
print(max_value) # 9
print(idx) # 3
Numpy
import numpy as np
my_list = [0, 5, 4, 9, -2, 6]
idx = np.argmax(my_list)
max_value = my_list[idx]
print(max_value) # 9
print(idx) # 3

mauro
- 504
- 3
- 14