EIGENVECTOR_CENT
Eigenvector centrality measures the importance of a node by accounting for both its number of connections and the quality of those connections. A node is central if it is connected to nodes that are themselves central.
This measure is common in social network analysis and bibliometrics to identify prestigious or influential entities.
The function returns a ranked list of nodes and their centrality scores, sorted from most to least central.
Excel Usage
=EIGENVECTOR_CENT(edges, weighted, max_iter)
edges(list[list], required): 2D array of edges [source, target, weight?].weighted(bool, optional, default: false): If True, use edge weights for calculations.max_iter(int, optional, default: 100): Maximum number of power iterations.
Returns (list[list]): 2D array of [node, score] pairs, sorted by score descending.
Example 1: Path graph eigenvector
Inputs:
| edges | |
|---|---|
| A | B |
| B | C |
| C | D |
Excel formula:
=EIGENVECTOR_CENT({"A","B";"B","C";"C","D"})
Expected output:
| Result | |
|---|---|
| C | 0.601501 |
| B | 0.601501 |
| A | 0.371748 |
| D | 0.371748 |
Example 2: Cycle graph eigenvector
Inputs:
| edges | |
|---|---|
| A | B |
| B | C |
| C | A |
Excel formula:
=EIGENVECTOR_CENT({"A","B";"B","C";"C","A"})
Expected output:
| Result | |
|---|---|
| A | 0.57735 |
| B | 0.57735 |
| C | 0.57735 |
Example 3: Star graph eigenvector
Inputs:
| edges | |
|---|---|
| Center | A |
| Center | B |
| Center | C |
Excel formula:
=EIGENVECTOR_CENT({"Center","A";"Center","B";"Center","C"})
Expected output:
| Result | |
|---|---|
| Center | 0.707107 |
| A | 0.408248 |
| B | 0.408248 |
| C | 0.408248 |
Example 4: Weighted eigenvector
Inputs:
| edges | weighted | ||
|---|---|---|---|
| A | B | 10 | true |
| A | C | 1 |
Excel formula:
=EIGENVECTOR_CENT({"A","B",10;"A","C",1}, TRUE)
Expected output:
| Result | |
|---|---|
| A | 0.707107 |
| B | 0.703597 |
| C | 0.0703597 |
Python Code
import networkx as nx
def eigenvector_cent(edges, weighted=False, max_iter=100):
"""
Calculate the eigenvector centrality for nodes.
See: https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.centrality.eigenvector_centrality.html
This example function is provided as-is without any representation of accuracy.
Args:
edges (list[list]): 2D array of edges [source, target, weight?].
weighted (bool, optional): If True, use edge weights for calculations. Default is False.
max_iter (int, optional): Maximum number of power iterations. Default is 100.
Returns:
list[list]: 2D array of [node, score] pairs, sorted by score descending.
"""
try:
def to2d(x):
return [[x]] if not isinstance(x, list) else x
edges = to2d(edges)
if not isinstance(edges, list) or not edges:
return "Error: edges must be a non-empty 2D list"
G = nx.Graph() # eigenvector_centrality works on directed but usually undirected in this context
if weighted:
G.add_weighted_edges_from([(str(row[0]), str(row[1]), float(row[2]) if len(row) >= 3 else 1.0) for row in edges if len(row) >= 2])
weight_arg = 'weight'
else:
G.add_edges_from([(str(row[0]), str(row[1])) for row in edges if len(row) >= 2])
weight_arg = None
if not G.nodes:
return "Error: No valid nodes or edges found in input"
try:
scores = nx.eigenvector_centrality(G, weight=weight_arg, max_iter=int(max_iter))
except nx.PowerIterationFailedConvergence:
return "Error: Power iteration failed to converge within max_iter"
# Sort by score descending, then by node name
sorted_scores = sorted(scores.items(), key=lambda x: (-x[1], x[0]))
return [[node, float(score)] for node, score in sorted_scores]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
2D array of edges [source, target, weight?].
If True, use edge weights for calculations.
Maximum number of power iterations.