find a minimum value in an array of floats

pjehyun picture pjehyun · Aug 17, 2010 · Viewed 232.3k times · Source

how would one go about finding the minimum value in an array of 100 floats in python? I have tried minindex=darr.argmin() and print darr[minindex] with import numpy (darr is the name of the array)

but i get: minindex=darr.argmin()

AttributeError: 'list' object has no attribute 'argmin'

what might be the problem? is there a better alternative?

thanks in advance

Answer

Greg Hewgill picture Greg Hewgill · Aug 17, 2010

Python has a min() built-in function:

>>> darr = [1, 3.14159, 1e100, -2.71828]
>>> min(darr)
-2.71828