• Source
    1.  
    2. def Parte2(G, k):
    3.  
    4. V = G.number_of_nodes()
    5. A = nx.adjacency_matrix(G)
    6. D = np.zeros((V,V))
    7.  
    8. for i in range(V):
    9. j = 1 / float(G.degree(i))
    10. D[i][i] = j
    11.  
    12. print "\nMatriz Delta-1:\n"
    13. print D
    14.  
    15. P = D*A
    16. NP = P
    17. i = 0
    18.  
    19. while i < k:
    20. NP = np.dot(NP, P)
    21. i = i + 1
    22.  
    23. print "\nMatriz P com k = ",k,":\n"
    24. print NP
    25.  
    26. print "\n w_power '",k,"' retirado da matriz P: \n"
    27. w_power = NP[0]
    28. print w_power
    29. X = sum(w_power)
    30. print "\nSoma do vetor: ", X
    31.  
    32. print "\n\nPower Method com n=5: "
    33. Parte2(G,5)
    34. print "\n\nPower Method com n=100: "
    35. Parte2(G,100)
    36.