def eigenvector_centrality_numpy(G, weight='weight', max_iter=50, tol=0):
 import scipy as sp
 from scipy.sparse import linalg
 if (len(G) == 0):
  raise nx.NetworkXPointlessConcept('cannot compute centrality for the null graph')
 M = nx.to_scipy_sparse_matrix(G, nodelist=list(G), weight=weight, dtype=float)
 (eigenvalue, eigenvector) = linalg.eigs(M.T, k=1, which='LR', maxiter=max_iter, tol=tol)
 largest = eigenvector.flatten().real
 norm = (sp.sign(largest.sum()) * sp.linalg.norm(largest))
 return dict(zip(G, (largest / norm)))

def eigenvector_centrality_numpy ( G , weight = 'weight' , max_iter = 50 , tol = 0 ) : import scipy as sp from scipy . sparse import linalg if ( len ( G ) == 0 ) : raise nx . NetworkXPointlessConcept ( 'cannot compute centrality for the null graph' ) M = nx . to_scipy_sparse_matrix ( G , nodelist = list ( G ) , weight = weight , dtype = float ) ( eigenvalue , eigenvector ) = linalg . eigs ( M . T , k = 1 , which = 'LR' , maxiter = max_iter , tol = tol ) largest = eigenvector . flatten ( ) . real norm = ( sp . sign ( largest . sum ( ) ) * sp . linalg . norm ( largest ) ) return dict ( zip ( G , ( largest / norm ) ) )
compute the eigenvector centrality for the graph g .