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