Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to Get Index of Maximum and Minimum Value of a List in Python. so without wasting time lets learn about of this.
How to get Index of Maximum and Minimum Value of a List in Python
get Index of Maximum and Minimum Value of a List in Python
to get Index of Maximum and Minimum Value of a List in Python just min() and list.index(). By using numpy.argmax() you can get index of maximum value of a list in python. Lets learn about of this by given below example:
import numpy list1 = [5,8,7,9,15] maxindex = numpy.argmax(list1) print(maxindex)
Output :4
How to get Index of Maximum and Minimum Value of a List in Python
to get Index of Maximum and Minimum Value of a List in Python just Use numpy.argmin(). By using numpy.argmin() you can get index of minimum value of a list in python. Lets learn about of this by given below example:
import numpy list1 = [5,8,7,9,15] maxindex = numpy.argmax(list1) print(maxindex)
Output :0
python list argmax
To get Index of Maximum and Minimum Value of a List in Python just Use numpy.argmin(). By using numpy.argmin() you can get index of minimum value of a list in python. Lets learn about of this by given below example:
import numpy list1 = [5,8,7,9,15] maxindex = numpy.argmax(list1) print(maxindex)
Output :0
Method 1: Use numpy.argmax()
By using numpy.argmax() you can get index of maximum value of a list in python. Lets learn about of this by given below example:
import numpy
list1 = [5,8,7,9,15]
maxindex = numpy.argmax(list1)
print(maxindex)
Output :
4
Method 2: Use numpy.argmin()
By using numpy.argmin() you can get index of minimum value of a list in python. Lets learn about of this by given below example:
import numpy
list1 = [5,8,7,9,15]
maxindex = numpy.argmax(list1)
print(maxindex)
Output :
0
Method 3: Use max() and list.index()
By using max() and list.index() you can get index of maximum value of a list in python. Lets learn about of this by given below example:
mylist = [5,8,7,9,15]
tmp = max(mylist)
index = mylist.index(tmp)
print(index)
Output :
4
Method 4: Use min() and list.index()
By using min() and list.index() you can get index of minimum value of a list in python. Lets learn about of this by given below example:
mylist = [5,8,7,9,15]
tmp = min(mylist)
index = mylist.index(tmp)
print(index)
Output :
0
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read