Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find a minimum value in an array of floats

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

like image 305
pjehyun Avatar asked Aug 17 '10 03:08

pjehyun


People also ask

How do you find the minimum value in an array in Python?

In python is very easy to find out maximum, minimum element and their position also. Python provides different inbuilt function. min() is used for find out minimum value in an array, max() is used for find out maximum value in an array. index() is used for finding the index of the element.

How do you find the smallest value in an array of objects?

Use JavaScript reduce() or Math method to get the min value in an array of objects. Using the Math functions with the spread operator (…) and sorting the array numerically with . sort() is a way to get the min value-form an array.


1 Answers

Python has a min() built-in function:

>>> darr = [1, 3.14159, 1e100, -2.71828] >>> min(darr) -2.71828 
like image 186
Greg Hewgill Avatar answered Sep 30 '22 17:09

Greg Hewgill