IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
argminmax.py
1 """@namespace IMP.EMageFit.argminmax
2  Utility functions to extract min/max from the inputs.
3 """
4 
5 
6 def argmin(sequence):
7  """ Argmin function: Returns the pair (min_value,min_index),
8  where min_index is the index of the minimum value
9  """
10  min_value = sequence[0]
11  min_index = 0
12  for i, s in enumerate(sequence):
13  if s < min_value:
14  min_value = s
15  min_index = i
16  return min_value, min_index
17 
18 
19 def keymin(dictionary):
20  """ return the key of the dictionary that has the minimum value """
21  ks = list(dictionary.keys())
22  min_key = ks[0]
23  min_value = dictionary[min_key]
24  for k in ks:
25  if dictionary[k] < min_value:
26  min_value = dictionary[k]
27  min_key = k
28  return min_value, min_key
29 
30 
31 def argmax(sequence):
32  """ Argmax function: Returns the pair (max_value,max_index),
33  where max_index is the index of the maximum value
34  """
35  max_value = sequence[0]
36  max_index = 0
37  for i, s in enumerate(sequence):
38  if s > max_value:
39  max_value = s
40  max_index = i
41  return max_value, max_index
42 
43 
44 def keymax(dictionary):
45  """ return the key of the dictionary that has the maximum value """
46  ks = list(dictionary.keys())
47  max_key = ks[0]
48  min_value = dictionary[max_key]
49  for k in ks:
50  if dictionary[k] > min_value:
51  min_value = dictionary[k]
52  max_key = k
53  return min_value, max_key
def keymax
return the key of the dictionary that has the maximum value
Definition: argminmax.py:44
def keymin
return the key of the dictionary that has the minimum value
Definition: argminmax.py:19
def argmax
Argmax function: Returns the pair (max_value,max_index), where max_index is the index of the maximum ...
Definition: argminmax.py:31
def argmin
Argmin function: Returns the pair (min_value,min_index), where min_index is the index of the minimum ...
Definition: argminmax.py:8