find a minimum value in an array of floats find a minimum value in an array of floats python python

find a minimum value in an array of floats


Python has a min() built-in function:

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


If you want to use numpy, you must define darr to be a numpy array, not a list:

import numpy as npdarr = np.array([1, 3.14159, 1e100, -2.71828])print(darr.min())

darr.argmin() will give you the index corresponding to the minimum.

The reason you were getting an error is because argmin is a method understood by numpy arrays, but not by Python lists.


You need to iterate the 2d array in order to get the min value of each row, then you have to push any gotten min value to another array and finally you need to get the min value of the array where each min row value was pushed

def get_min_value(self, table):    min_values = []    for i in range(0, len(table)):        min_value = min(table[i])        min_values.append(min_value)    return min(min_values)