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