-
Notifications
You must be signed in to change notification settings - Fork 1
/
dict_test.py
56 lines (27 loc) · 919 Bytes
/
dict_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 11 13:42:23 2021
@author: karas
"""
import numpy as np
import operator
# keys = [(i, j) for i in range(3) for j in range(3)]
# values = [i for i in np.random.rand(9)]
# test_dict = dict(zip(keys, values))
test_dict = {(0,0):2.57, (0,1):0.73, (1,0):0.67, (1,1):3.55}
left_index = [i[0] for i in test_dict.keys()]
right_index = [i[1] for i in test_dict.keys()]
left_index = np.array(left_index)
left_index = np.unique(left_index)
right_index = np.array(right_index)
right_index = np.unique(right_index)
unique = []
last_dict = {}
for l_idx in left_index:
inter_dict = {}
for j in list(test_dict.keys()):
if l_idx == j[0]:
inter_dict[j] = test_dict[j]
x = min(inter_dict.items(), key=operator.itemgetter(1))[0]
last_dict[x] = test_dict[x]