0

{'X050412_1_0000_1_4': {'0-4': 64.9516586968339, '2-3': 47.573389284767174, '1-2': 29.414889381739993, '0-1': 20.137499912849165, '0-2': 48.36841808990657, '0-3': 65.07665932728878, '1-3': 58.326301639483376, '3-4': 42.477331382632784, '1-4': 47.380533137671634, '2-4': 18.995337464493748}, 'X050412_1_0000_1_5': {'0-4': 74.45548880223673, '2-3': 42.921786085506746, '1-2': 22.297921437434468, '0-1': 16.755486281812296, '0-2': 31.640265835324445, '0-3': 49.53140665618129, '1-3': 55.29908155494086, '3-4': 25.4227462686469, '1-4': 78.22578893907047, '2-4': 61.73419510554909}, 'X050412_1_0000_1_6': {'0-4': 53.36246109354403, '2-3': 49.125438624810265, '1-2': 26.33647295558006, '0-1': 27.165619713343553, '0-2': 53.21604990987211, '0-3': 31.972624680029007, '1-3': 34.38869991232585, '3-4': 35.126226807472506, '1-4': 33.294628738732015, '2-4': 23.60048014617499}} Suppose that I've a graph represented like this and i Want to create to convert it into matrix form.

Omar
  • 37
  • 5

1 Answers1

0
for k,v in dataset.distances.items():
if k not in diz2:
    diz2[k] = {}
for k2,v2 in v.items():
    res = tuple(map(int, k2.split('-')))
    if res not in diz2:
        diz2[k][res] = v2

def convert(diz5):
temp_x = max([cord[0] for cord in diz5.keys()])
temp_y = max([cord[1] for cord in diz5.keys()])
res2 = [[0] * (temp_y + 1) for ele in range(temp_x + 1)]
for (i, j), val in diz5.items():
    res2[i][j] = val
#print("The dictionary after creation of Matrix : " + str(res2))
return  res2
Omar
  • 37
  • 5