python - Error while calculating math.sqrt -
this question has answer here:
i faced strange error, , wasted 2 hours on it, couldn't come explanation
import math ipd={1:[2,3],2:[1],3:[1],4:[5,6,7],5:[4,6],6:[4,5],7:[4]} gkeys = [k k in ipd.iterkeys()] key_map = {} x in range(len(gkeys)): key_map[x] = gkeys[x] val = len(gkeys) #adj matrix... w = [[0.0]*val]*val print w in range(len(gkeys)): j in range(len(gkeys)): #if , j has edge... if key_map[j] in ipd[key_map[i]]: deg1 = len(ipd[key_map[j]]) deg2 = len(ipd[key_map[i]]) v = 1.0/math.sqrt(deg1*deg2) w[i][j] = v print i,j,deg1,deg2,w[i][j], w[j][i]
here whole problem
for i=3 , j=5 first w[i][j] 0.4248.. i=5, , j=3 w[j][i] giving 0.5, how possible.
thanks!
w = [[0.0]*val]*val
the above gives val
copies of the exact same list. try this:
a = [[0] * 4] * 4 print a[0][0] = 99 print
output:
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] [[99, 0, 0, 0], [99, 0, 0, 0], [99, 0, 0, 0], [99, 0, 0, 0]]
Comments
Post a Comment